Which fix removes the bug?
def total(items):
sum = 0
for i in items:
sum += i
return sum(items)
- Return the accumulator, not
sum(items) - Return the accumulator, not
items.sum() - Rename the loop variable from
iton - Initialise
sumto None before the loop
The local
Play Problem Solving ▸
sum shadows the builtin, so calling it raises TypeError.