solve problem 2 with python