Problem #3 using Python