PythiloLesson 13 of 30 · progress kept in this browser

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())  # False
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.

Next: Lists