problem
UnboundLocalError: local variable ‘xxx’ referenced before assignment
Analysis: The
variable n has been defined outside the function, and when the variable is operated inside the function, such an error will be encountered during runtime: The
core reason: mainly because the interpreter is not clear whether the variable is a global variable or a local variable.
Demonstration of error case:
re-organized code: