Problem 24, Python