Practice: Point class#

Download starter code

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 and y values.

  • A method named get_x that returns the x value of this Point .

  • A method named get_y that returns the y value of this Point .

  • A method named set_x that takes a new x value and updates this Point β€˜s x to the parameter.

  • A method named set_y that takes a new y value and updates this Point β€˜s y to the parameter.

  • A method name display that returns a str representation of the point. It should return '(x, y)' where x is its x value and y 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)'