Solves Problem 26 in Python