Solves Problem 28 in Python