Do problem 16 using Python.