Week 5 Live Lecture
Software Refactoring Exercise
Chapter 1: Software refactoring exercise
Warming up
Download sequence.py. Examine the code.
- There are two classes:
FibonacciSequenceandTriangleNumberSequence. Try to understand what each class does. - What does the
term()method of each class return? - How is the
lengthattribute used in each class? - The
__iter__()and__next__()methods allow Python to treat these classes as iterable sequences. - Look at the test code at the end of the script to get a feel of how both classes are used.
Run the code (python3 sequence.py). It should work and generate the correct sequences.