Point

Report a typo

Create a class named Point that represents a point in a two-dimensional space. The class should have a constructor that takes two parameters, x and y, representing the coordinates of the point on the plane.

The class should have a method dist that takes another instance of the Point class as a parameter and returns the Euclidean distance between the current point and the given point.

For Point(x1, y1) and Point(x2, y2), calculate the distance according to the formula:

d=(x1x2)2+(y1y2)2d = \sqrt{(x_1 - x_2)^2 + (y_1 - y_2)^2}

Here's an example to illustrate how to use the class:

p1 = Point(1.5, 1)
p2 = Point(1.5, 2)

print(p1.dist(p2))  # 1.0

Please note that you only need to create the class and its methods as described.

Write a program in Python 3
class Point:
pass
___

Create a free account to access the full topic