finished problem 30  in python