From aa03e5e838c5d8ed3f05f5316d8f7a6cc4d2e1dc Mon Sep 17 00:00:00 2001 From: lolabird Date: Fri, 16 Feb 2024 10:53:05 -0700 Subject: [PATCH] Change selected return values to tuples and fix formatting --- thinkcspy/Chapter-17-Exercises/points.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/thinkcspy/Chapter-17-Exercises/points.py b/thinkcspy/Chapter-17-Exercises/points.py index dc71613..ac36e87 100644 --- a/thinkcspy/Chapter-17-Exercises/points.py +++ b/thinkcspy/Chapter-17-Exercises/points.py @@ -21,10 +21,10 @@ class Point: dx = self.x - pnt.getX() dy = self.y - pnt.getY() - return math.sqrt(dx**2 +dy**2) + return math.sqrt(dx**2 + dy**2) def reflect_x(self): - return "(" + str(self.x) + ", " + str(-self.y) + ")" + return (self.x, -self.y) def slopeFromOrigin(self): return self.y / self.x @@ -32,24 +32,24 @@ 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 - return "(" + str(m) + ", " + str(b) + ")" + return (m, b) def move(self, pnt): self.x += pnt.getX() self.y += pnt.getY() - return "(" + str(self.x) + ", " + str(self.y) + ")" + return (self.x, self.y) def __str__(self): return "x=" + str(self.x) + ", y=" + str(self.y)