Problem #10 in Python