lesson
Average, or zero
objective: debugging exercise · lists & edge cases · hard
Task type: fix broken code
average_or_zero(nums) should return the average of the numbers in the list, or 0 if the list is empty.
View the authored lesson overview →fix this code so it matches
average_or_zero([2, 4, 6]) is 4. average_or_zero([10]) is 10. average_or_zero([]) is 0. average_or_zero([-2, 2]) is 0.
- ○Passes the visible tests
- ○Passes the hidden tests (edge cases)
Go deeper
Lesson resources
average_or_zero.pyattempt 0
1
2
3