$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #168

Which fix removes the bug?

total = 0
def add(n):
    total += n
  1. Declare total global
  2. Return the new total
  3. Initialise total inside
  4. Pass total as an arg
Assigning inside a function makes the name local, so reading it first is an error.
Play Problem Solving ▸