Added Python version of Problem 5