Solve problem 4 using Python.