Complete Exercise 2 in Chapter 16 of Think Python