Fixed solution for problem 7 in Python.