solution to problem 34 in python