Add solution for problem 3 in Python