Python code for problem 2