Working version of problem3.py