Refactored avg.py to eliminate The Tower of Elif.