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