solved problem1 using python