Completed exercise 5 in Python