BugLab005 / 020up to 100
mathloopscountersmedium

One Too Many

The function average(numbers) computes the mean of a list, and passing_grade(scores) uses it to decide if a student passes (average >= 60).

A student with scores [60, 70, 80] — average 70 — should clearly pass. But the function says 'fail'.

The arithmetic logic looks correct. Where is the counter going wrong?

# your fix
+ must use for
- must not call sum()
- must not call len()
hint 2after hint 1
hint 3after hint 2
solution

Read the code. Before running anything: what does the last line below give?

def average(numbers):
total = 0
count = 1
for n in numbers:
total += n
count += 1
return total / count
def passing_grade(scores):
avg = average(scores)
if avg >= 60:
return "pass"
return "fail"
>>> average([60, 70, 80])