Solve problem 23 using Python.