solution to problem 17 in python