Problem 1 in Python, done better.