Solution for problem #13 in Python.