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

Which fix removes the bug?

for n in [1, 2, 3]:
    total = 0
    total += n
print(total)  # expected 6
  1. Use total = total + n here
  2. Loop over range(3) instead
  3. Set total = 0 before the loop
  4. Print total inside the loop body
The accumulator is reset on every pass, so only the last value survives.
Play Problem Solving ▸