solution to problem 32 in python