Return error messages for slopeIntercept method
This commit is contained in:
parent
da24d97382
commit
42c23059c4
1 changed files with 8 additions and 0 deletions
|
|
@ -32,6 +32,14 @@ class Point:
|
|||
def slopeIntercept(self, pnt):
|
||||
dx = self.x - pnt.getX()
|
||||
dy = self.y - pnt.getY()
|
||||
|
||||
# Accounting for points of failure (divide by 0)
|
||||
if dx == 0:
|
||||
if dy == 0:
|
||||
return "Cannot calculate slope of a single point."
|
||||
else:
|
||||
return "Cannot calculate slope of a vertical line."
|
||||
|
||||
m = dy / dx
|
||||
b = self.y - m*self.x
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue