CS106 Summer 2023 Michael Eckmann Lab 11 July 27, 2026 ================== Purpose: To get familiar with the following topics editing an existing class to add methods writing a class and overriding operators ================== PROBLEM 1 ================== Starting with the rectangle.py module containing the class Rectangle, write 3 methods in Rectangle to handle scaling a Rectangle by some factor, and methods to compute area and perimeter e.g. import rectangle myRect1 = rectangle.Rectangle(2,3) myRect1.scale(4) # should make the rectangle now be a 4*2=8 by 4*3 = 12 size a = myRect1.area() # a should be 8*12 = 96 p = myRect1.perimeter() # p should be 8+12+8+12 = 40 ================== PROBLEM 2 ================== Create 2 modules for this problem. One named Fraction and one named Work_With_Fractions. Work_With_Fractions will have code that will ask the user for a numerator and denominator for 2 fractions. Your code should create 2 objects of type Fraction with that data. Multiply and divide these fractions (not their floating point representations) and add and subtract these fractions (not their floating point representations). You are required to store fractions in lowest terms. e.g. if I try to create a fraction with a numerator 18 and a denominator 24, you should figure out that this is the fraction 3/4 and store it in that fashion (with 3 as numerator and 4 as denominator). **** Note well: use the gcd function in the math module import math math.gcd(__,__) and use that to get your numerator and denominator in lowest terms. Fractions can also be negative, make sure to take this into account in some way. In Fraction, you should have methods to multiply, divide, add and subtract that do those operations to two Fraction objects. use these method names to override the operators +, -, *, / __add__ __sub__ __mul__ __truediv__ ====== Example input (preceded by a >) and output of your program: Enter a numerator > 60 Enter a denominator > 105 You entered the fraction 4 / 7 Enter a numerator > 2 Enter a denominator > 3 You entered the fraction 2 / 3 (4 / 7) * (2 / 3) = (8 / 21) (4 / 7) / (2 / 3) = (6 / 7) (4 / 7) + (2 / 3) = (26 / 21) (4 / 7) - (2 / 3) = (-2 / 21) =========== PROBLEM 3 =========== Edit your Fraction class and add the following comparison operators: __gt__ __lt__ __eq__ __ge__ __le__ Test them out in a similar way you tested out the Fraction class in problem 1. Submit to the Spring: rectangle.py testrectangles.py Fraction.py Work_With_Fractions.py