From e3b71b9fdb925bfabed52acebbdaeefe924a7f92 Mon Sep 17 00:00:00 2001 From: lolabird Date: Fri, 16 Feb 2024 17:13:55 -0700 Subject: [PATCH] Add solutions from problems 9 through 12 --- thinkcspy/Chapter-17-18-Exercises/rectangle.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/thinkcspy/Chapter-17-18-Exercises/rectangle.py b/thinkcspy/Chapter-17-18-Exercises/rectangle.py index eb9f042..855a984 100644 --- a/thinkcspy/Chapter-17-18-Exercises/rectangle.py +++ b/thinkcspy/Chapter-17-18-Exercises/rectangle.py @@ -15,7 +15,21 @@ class Rectangle: def __str__(self): return "Lower Left Coordinates: {}; Width: {}; Height: {}".format(self.pos, self.width, self.height) + def area(self): + return self.width * self.height + + def perimeter(self): + return self.width * 2 + self.height * 2 -r = Rectangle(Point(4, 5), 6, 5) + def transpose(self): + width = self.width + self.width = self.height + self.height = width + + return self + + +r = Rectangle(Point(0, 0), 10, 5) print(r) +print(r.transpose()) \ No newline at end of file