Exercise 3 using python