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