python solution for problem 30