Add case to account for vertical slopes or same points in method

This commit is contained in:
lolabird 2024-03-01 10:54:16 -07:00
commit f9b7352672

View file

@ -31,6 +31,9 @@ class Point:
return (self.x, -self.y)
def slopeFromOrigin(self):
if self.x == 0:
return None
return self.y / self.x
def slopeIntercept(self, pnt):
@ -79,3 +82,5 @@ class Point:
def __str__(self):
return "x=" + str(self.x) + ", y=" + str(self.y)
p = Point(0, 5)
print(p.slopeFromOrigin())