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
xandyvalues.A method named
get_xthat returns thexvalue of thisPoint.A method named
get_ythat returns theyvalue of thisPoint.A method named
set_xthat takes a newxvalue and updates thisPointβsxto the parameter.A method named
set_ythat takes a newyvalue and updates thisPointβsyto the parameter.A method name
displaythat returns astrrepresentation of the point. It should return'(x, y)'wherexis itsxvalue andyis 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)'