solution to problem 15 in python