python code for problem 2