Solving p5 of the python challenge