$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · easy · #85

Which fix removes the bug?

def total(items):
    sum = 0
    for i in items:
        sum += i
    return sum(items)
  1. Return the accumulator, not sum(items)
  2. Return the accumulator, not items.sum()
  3. Rename the loop variable from i to n
  4. Initialise sum to None before the loop
The local sum shadows the builtin, so calling it raises TypeError.
Play Problem Solving ▸