0
What is the problem with this code? Finding distance and slope using python Oop
class Line(object): def __init__ (self,coor1,coor2): # We are finding the slope and the distance self.coor1 = coor1 self.coor2 = coor2 def distance (self): x1,y1 = self.coor1 x2,y2 = self.coor2 return (((x2-x1)**2) + ((y2-y1)**2))**0.5 def slope (self): x1,y1 = self.coor1 x2,y2 = self.coor2 return float(((y2-y1)/(x2-x1))) coordinate1 = (3,2) coordinate2 = (8,10) a = Line(coordinate1, coordinate2) a.distance() a.slope()
1 Réponse
+ 2
class Line:
def __init__ (self,coor1,coor2):
# We are finding the slope and the distance
self.coor1 = coor1
self.coor2 = coor2
def distance (self,Line a):
x1= self.coor1
y1 = self.coor2
x2=a.coor1
y2=a.coor2
return (((x2-x1)**2) + ((y2-y1)**2))**0.5
def slope (self,Line a):
x1= self.coor1
y1 = self.coor2
x2=a.coor1
y2=a.coor2
return float(((y2-y1)/(x2-x1)))
Line coordinate1(3,2)
Line coordinate2(8,10)
coordinate1.distance(coordinate2)
coordinate1.slope(coordinate2)