Question: A point in two - dimensions can be represented by an x - and y - coordinate. In this problem, you will write a Point
A point in twodimensions can be represented by an x and ycoordinate. In this problem, you will write a Point class to store and work with such points.
The init definition for the Point class is provided. Note that this accepts two arguments: the x and ycoordinates of the point.
Also included is the repr method, which outputs a canonical string representation of the point. Do not change this method, as we use it for tests. Note that the output of repr could be copied into the interpreter in order to create an identical point. This is a characteristic of good repr methods.
Task
Write a methoddisttopointself other: Point float
that returns the Euclidean distance between the points self and other. You may use math.sqrt
Write a method isnearself other: Point bool
that determines if two points are close. Two points are considered close if their Eucldiean distance is less than the global constant EPSILON.
Remember that you can use disttopoint in this method by evoking self.disttopoint.
Write a method addpointself other: Point None
that adds the x and y component of other to the x and y component of self. Note this method returns None and therefore the change only modifies the current instance of self.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
