Solve problem 1 by Python.