Solved problem 10 with Python