Python 3:UnboundLocalError:賦值前引用的局部變量

| | | | |

以下代碼給出錯誤UnboundLocalError: local variable "Var1" referenced before assignment:

Var1 = 1 Var2 = 0 def function(): if Var2 == 0 和 Var1 > 0: print("Result One") elif Var2 == 1 and Var1 > 0: print("結果二") elif Var1 < 1: print("Result Three") Var1 =- 1 function() 

我該如何解決這個問題?感謝您的幫助!