ex16.py with extra credit