在「count + = 1」時拋出錯誤。我試圖讓它成爲一個全球性的,它仍然給了一個問題。這不過是一個笑話而已,但我想知道它爲什麼不起作用。UnboundLocalError:分配前引用的本地變量'count'
import math
def delT():
#inputs
#float inputs
#do math
#print results
global count
count=0
def getAndValidateNext():
#print menu
getNext=input("select something")
acceptNext=["things","that","work"]
while getNext not in acceptNext:
count+=1
print("Not a listed option.")
if count==5:
print("get good.")
return
return(getAndVadlidateNext())
if getNext in nextRestart:
print()
return(delT())
if getNext in nextExit:
return
getAndVadlidateNext()
delT()
請完整追溯。如果我的眼睛看不到,該功能不會被調用... –
什麼是'getAndVadlidateNext'? – user2357112
[Python嵌套函數變量作用域]的可能重複(https://stackoverflow.com/questions/5218895/python-nested-functions-variable-scoping) – janos