ex5.py with extra credit