finished ex40.py