Solves Problem 1 in Python