Complete Exercise 3 in Chapter 9 of Think Python