Complete Exercise 4 of Chapter 9 of Think Python