For Python 3 Write a point class that includes a constructor that takes 2 argume
ID: 3712040 • Letter: F
Question
For Python 3 Write a point class that includes a constructor that takes 2 arguments, x and y. Write an instance method that takes a point as an argument and returns the distance between the 2 points. For Python 3 Write a point class that includes a constructor that takes 2 arguments, x and y. Write an instance method that takes a point as an argument and returns the distance between the 2 points. Write a point class that includes a constructor that takes 2 arguments, x and y. Write an instance method that takes a point as an argument and returns the distance between the 2 points.Explanation / Answer
import math
class point: #defne class name
def __init__(self,x,y): #defines the constructor
self.x=x
self.y=y
def distance(self,p): #instance method to calculate the distance
dis=math.sqrt((p.y-self.y)*(p.y-self.y) + (p.x-self.x)*(p.x-self.x))
return dis
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.