Code for assignment 3