solved problem2 using python