Completed ex4.py