Solve problem 27 using Python.