Completed ex9.py