Solve Problem 11 in Python