# Untitled

unknown

plain_text

4 years ago

706 B

1

Indexable

Never

^{}

# Create a class Point that will represent a point in space. # Its constructor needs two parameters xx and yy, # the coordinates of a point on the plane. # # The class should have a method dist that takes another instance of Point # and returns the Euclidean distance between these two points. # # For Point(x1, y1) and Point(x2, y2), # calculate the distance according to the formula: # d = sqrt( (x1-x2)^2 + (y1 - y2)^2 ) import math class Point(): def __init__ (self, xx, yy): self.xx = xx self.yy = yy def dist(self, p2): return math.sqrt( (self.xx - p2.xx)**2 + ( self.yy - p2.yy )**2 ) p1 = Point(1.5, 1) p2 = Point(1.5, 2) print(p1.dist(p2))