Problem 2 in Python.