Please help me this problem! Please follow the format of the picture!!! It\'s Py
ID: 3711495 • Letter: P
Question
Please help me this problem! Please follow the format of the picture!!!
It's Python 3 style!!!!
Problem 2. (2D Point) Define a data type Point in point.py that represents a point in 2D. The data type must support the following API method description w point p from the given r and y values Point (x, y p.distanceTo() the Euclidean distance between p and q string representation of p as str(p) the string representation of p as ,(x, y), python point.py 01 1 o p1-Co.0, 1.0 p2 (1.o, 0.0) d(pl, p2) 1.41421356237Explanation / Answer
import math
import sys
#point class
class Point:
def __init__(self, x, y):
#assigning the passed values to the point object
self._x = x
self._y = y
#string reperesentation of the point
def __str__(self):
return "Point("+str(self._x)+","+str(self._y)+")"
#function to calculate the distance
def distanceTo(self, other):
#calculating the distance
dx = self._x - other._x
dy = self._y - other._y
#returning the distance
return math.sqrt(dx**2 + dy**2)
#end of funtion
#end of class
#main method to run the program
def _main():
#rreading the arguements
x1,y1,x2,y2 =map(float,sys.argv[1:])
#creating the points
p1 = Point(x1,y1)
p2 = Point(x2,y2)
#printing the points
print("p1 = ",str(p1))
print("p2 = ",str(p2))
#printing the points distance
print( "d(p1,p2) = ", p1.distanceTo(p2) )
#end of main function