Solved problem 10 in python