Solve problem 54 using Python.