Python Reading
Key Ideas
- A fraction can be implemented as a class. A fraction
consists of two integers: a numerator and a denominator.
- An instance of a class is mutable.
- A mutator method is a method of a class that changes the
values of one or more instance variables.
In-Class Activity
- Take a look at fraction.py.
- In the Fraction class, identify the instance variables.
- In the Fraction class, identify the constructor.
- For each method in the Fraction class, identify whether or not
it is a mutator method.
- Trace what happens when the simplify method is called when
the numerator value is 36 and the denominator value is 48.
- Explain why the add method is correct.
Active Learning
- Make sure you fully understand the fraction.py file. Ask questions
as necessary.
- Add a multiply method to the program and test that it
works properly. Ask MacKenzie or John to check your solution.