Local and global scope
A name assigned inside a function is local: it exists only while that call runs, and code outside cannot see it. To look a name up, Python checks the local scope, then any enclosing function, then the module level (global), then the builtins.
rate = 2 # global
def scale(x):
result = x * rate # reads the global
return result
print(scale(5)) # 10
print("result" in globals()) # FalseAssigning makes a name local
If a function assigns to a name anywhere in its body, that name is local for the whole function. So count += 1 on a global raises UnboundLocalError, unless the function declares global count first.
count = 0
def bump():
global count
count += 1
bump()
print(count) # 1global works, but a function that changes globals gives different answers depending on what ran before it. Pass values in as arguments and hand results back with return. And do not name your variables sum, max or list: that hides the builtin.
Your task
Rewrite the starter without the global: add_points(total, points) returns the new total, and tally(rounds) starts from 0, uses add_points for each number in rounds, and returns the result.
The explanation opens here once every check passes.