solving ex2 - coursera