Add case to account for vertical slopes or same points in method
This commit is contained in:
parent
bf78a613d3
commit
f9b7352672
1 changed files with 5 additions and 0 deletions
|
|
@ -31,6 +31,9 @@ class Point:
|
||||||
return (self.x, -self.y)
|
return (self.x, -self.y)
|
||||||
|
|
||||||
def slopeFromOrigin(self):
|
def slopeFromOrigin(self):
|
||||||
|
if self.x == 0:
|
||||||
|
return None
|
||||||
|
|
||||||
return self.y / self.x
|
return self.y / self.x
|
||||||
|
|
||||||
def slopeIntercept(self, pnt):
|
def slopeIntercept(self, pnt):
|
||||||
|
|
@ -79,3 +82,5 @@ class Point:
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "x=" + str(self.x) + ", y=" + str(self.y)
|
return "x=" + str(self.x) + ", y=" + str(self.y)
|
||||||
|
|
||||||
|
p = Point(0, 5)
|
||||||
|
print(p.slopeFromOrigin())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue