Solved problem 9 with python