What is the problem with this code? Finding distance and slope using python Oop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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()

20th Sep 2019, 1:01 PM
Prince Andrew Prosper
Prince Andrew Prosper - avatar
1 Answer
+ 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)
20th Sep 2019, 1:16 PM
KfirWe
KfirWe - avatar