Complete Exercise 2 in Chapter 4, Section 3 of Think Python