Problem #5 in python