Problem 16 Solution - Python