Exercise 9 in Python the Hard Way