solved problem 6 in python