Read the error, find the cause
Debugging means systematically locating and correcting defects. Syntax errors prevent parsing; runtime errors arise while a program runs; logic errors produce incorrect results.
scores = [12, 15, 9]
total = 0
for score in scores:
total = score
mean = total / len(scores)
print(mean)The program runs but the output is incorrect. Fix the logic error without using sum().
Suggested solution
scores = [12, 15, 9]
total = 0
for score in scores:
total += score
mean = total / len(scores)
print(mean) # 12.0Extension
Adapt the program to deal safely with an empty list.
