Completed Problem 172 in python