midway through problem 3 in python.