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

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
  

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