python solution for problem 16