Added python code for question 3.