A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-54.py
1defouter():
2n=1
3definner():
4nonlocaln
5n+=10
6inner()
7returnn
8print(outer())
Scope
Answer & explanation
Console output
11
Why
The nonlocal keyword binds a name to the nearest enclosing function scope, letting inner reassign outer's local n rather than shadowing it. So n += 10 updates outer's variable in place, and outer returns 11. Without nonlocal, this assignment would raise an error or create a separate local in inner.