-5
我遇到了一個錯誤,我嘗試了一段時間的處理。轉讓之前的參考
if outerball.pos.x >= (self.r - 0.1):
if self.rotations == 0:
stopt = time.time ()
onerot = stopt - startt
print(onerot)
self.rotations += 1
# update variable outputs
timey.text = "time: %1.f" % onerot + " seconds"
誤差爲timey.text = "time: %1.f" % onerot + " seconds" UnboundLocalError: local variable 'onerot' referenced before assignment
我用盡全球化的變量,但它仍然未作出了區別。 有人可以解釋我如何解決這個問題。
感謝
'onerot'只值時分配符合'if條件' – haifzhan
問問你自己:當你的if塊沒有執行時'onerot'的值是多少? – jmoerdyk
我要指出你[這個問題](http://stackoverflow.com/questions/15367760/unboundlocalerror-local-variable-referenced-before-assignment-when-reading-from)哪些遭受同樣的問題像你一樣:你有一個有條件定義的變量。 –