finished challenge8.py (needs testing)