Function for coursera

assignment 2