ex6.py with extra credit