Exercise 45 from Learn Python the Hard Way.