Exercise 36 of "Learning Python The Hard Way".