Problem 39, Python