python code for problem 3