solution to problem 14 in python