Final Function code for peer assessment

This is the final code for Assignment 2