Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5. Write a class that represents a point in a 2D coordinate plane and call it Po

ID: 3903748 • Letter: 5

Question

5. Write a class that represents a point in a 2D coordinate plane and call it Point. The constructor for a point object should take both an x and a y coordinate. The class should also provide a getDistance function that takes another point, and returns the distance between itself and the other point. Use the following code, you should not need to modify provided code, just add the class as described. 213 Final Exam.md 6/11/2018 import math # TODO: define a class . Point, which represent a location in the coordinate plane # The class should have a constructor that takes both and . x' and a "y value # The class should have a "getDistance' function that returns the distance between t the point and another point object # NOTE: you should not modify any of the code below this line a Point(1, 1) b-Point (1, 2) dist a.getDistance(b) print ("the distance is: str (dist)) c = Point(5, 7) dist a.getDistance(c) print("the distnace is:"str (dist)) dist b.getDistance(c) print("the distance is: str(dist)) Example output: the distance is: 1.6e the distnace is: 7.211102550927978 the distance is: 6.4031242374328485

Explanation / Answer

class Point: def __init__(self, x, y): self.x = x self.y = y def getDistance(self, other): return ((self.x - other.x)**2 + (self.y - other.y)**2) ** 0.5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote