added assignment 3 question 4 code