Complete Exercise 5 in Chapter 9 of Think Python