Problem 27, Python