python doomsday solution for problem 19