Problem 1 Solution in Python