Solves Problem 25 in Python