From 42c23059c42c162b48bc2dbcee95b941d583bcc7 Mon Sep 17 00:00:00 2001 From: lolabird Date: Fri, 16 Feb 2024 10:29:31 -0700 Subject: [PATCH] Return error messages for slopeIntercept method --- thinkcspy/Chapter-17-Exercises/points.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/thinkcspy/Chapter-17-Exercises/points.py b/thinkcspy/Chapter-17-Exercises/points.py index f98c61e..dc71613 100644 --- a/thinkcspy/Chapter-17-Exercises/points.py +++ b/thinkcspy/Chapter-17-Exercises/points.py @@ -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