I have problem which cannot fix. I get the error
UnboundLocalError: local variable 'checking' referenced before assignment
My code
def volume_checker_first_stage(volume1,volume2,withdraw_minimun):
if volume1>volume2:
quantity = volume2
if quantity > withdraw_minimun:
checking = True
return quantity, checking
elif volume2>volume1:
quantity = volume1
if quantity > withdraw_minimun:
checking = True
return quantity, checking
else:
return None,None
将checking
初始化为False
作为函数的第一行以避免此错误。
As the first line of the body of your function, code this:
checking = False
You have a return
statement that returns the value of checking
, but your code doesn't always set it. Referenced before assignment
means your return
statement asked for the value of the variable before your code assigned it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.