Solves Problem 20 in Python