Reference no: EM132206567
Write a module called point. The module's code is intended to represent and manipulate points in 2-dimensional space. An important part of writing this module is deciding how to represent a point. If you pick an appropriate representation, then the functions listed below will each be just one or two lines of code.
a) make_point is passed 2 parameters, x and y (representing the x and y co-ordinates of a point). It is up to you to decide what this function should return. Here is an example call. It creates a point whose x co-ordinate is 1 and whose y co-ordinate is 4.
>>> p1 = point.make_point(1,4)
b) getxy is passed one parameter, a point p. It returns a tuple of length 2, representing the x and y co-ordinates of p. Continuing with the above example:
>>> point.getxy(p1) (1, 4)
c) move_point is passed three parameters: a point p, an integer dx, and an integer dy. It changes the x and y co-ordinates of the point p by adding dx to p's x co-ordinate, and dy to p's y coordinate. It returns nothing. For example, continuing with the above code:
>>> point.move_point(p1, 2, 1) \
>>> point.getxy(p1) (3, 5)
d) distance is passed 2 parameters p1 and p2, both of which are points. It returns the distance between p1 and p2. Continuing on with the previous examples:
>>> p2 = point.make_point(4, 6)
>>> point.distance(p1, p2)
1.4142135623730951
>>> point.move_point(p2, 3,2)
>>> point.distance(p1, p2)