Solve problem 21 using Python.