Which fix removes the bug?
total = 0
def add(n):
total += n
- Declare total global
- Return the new total
- Initialise total inside
- Pass total as an arg
Assigning inside a function makes the name local, so reading it first is an error.
Play Problem Solving ▸