Scope: Local vs Global: Coding lesson for kids
In “Scope: Local vs Global”, children learn about def add(a, b): total = a + b return total; print(total) # outside the function; result = add(2, 3) print(result).
def add(a, b): total = a + b return total: total is LOCAL — it can only be seen inside this function.
print(total) # outside the function: This crashes with a NameError — total was never created out here, only inside add().
result = add(2, 3) print(result): The right way: return the value and store it — prints 5.
This lesson is part of Python in Coding at Pearls Valley Academy — Real code, beginner-friendly syntax.
Each lesson starts with a short narrated, animated explanation, then hands-on practice. A wrong answer gets a gentle hint, never a penalty, and children earn stars and pearls as they go.