Practice: Point class
Practice: Point class#
Define a class Point
that represents a 2D point (x, y)
in the file point.py
.
The Point
class should have fields for the x
and y
coordinates and should have the following methods.
An initializer that takes the
x
andy
values.A method named
get_x
that returns thex
value of thisPoint
.A method named
get_y
that returns they
value of thisPoint
.A method named
set_x
that takes a newx
value and updates thisPoint
βsx
to the parameter.A method named
set_y
that takes a newy
value and updates thisPoint
βsy
to the parameter.A method name
display
that returns astr
representation of the point. It should return'(x, y)'
wherex
is itsx
value andy
is its y value.
For example, your class should have the following behavior (return value shown in comments). This is essentially the same as main.py
(which you donβt need to edit).
p = Point(1, 2)
p.get_x() # 1
p.set_y(4)
p.display() # '(1, 4)'