A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-174.py
1x="global"
2defouter():
3x="enclosing"
4definner():
5returnx
6returninner()
7print(outer())
Scope
Answer & explanation
Console output
enclosing
Why
Python resolves a free variable by searching scopes in LEGB order: Local, Enclosing, Global, then Builtin. inner has no local x, so the search moves outward to outer's enclosing scope and finds 'enclosing', stopping there before it would ever reach the global x. Enclosing function scope wins over global scope.