Solves Problem 39 in Python