Add solution for problem 4 written in Python