Problem 8, Python solution.