where?
When executing a python program, report this error.
Why?
Variable scope problems, variables defined in the branch can be correctly obtained when the condition is met, and the error is reported when the condition is not met.
The same?
Pull the variable from the branch to the branch, or define the variable in another branch, so that it is defined all the time to the access
Error code
def show_error (number): # When this condition is satisfied, result can be obtained correctly, and when not satisfied, the result variable if number <=: result = number print (Result) if __name__ = = ' __main__ ': for i in range: show_error (i)
Correct code
def show_error (number): # solution 1 result = 1 if number <=: result = number # solution 2 # E LSE: # result =-1 print (result) if __name__ = = ' __main__ ': for i in range: show_error (i)
Python-local variable ' Raw_password ' referenced before assignment