Added the solutin to Problem 31 in Python.