win=0
def fun():
win+=1
print(win)
a = 0
while True:
if a == 0:
fun()
Asked
Active
Viewed 664 times
-3

Jonas Byström
- 25,316
- 23
- 100
- 147

ax39T-Venom
- 32
- 1
- 5
-
2Possible duplicate of [referenced-before-assignment-error-in-python](https://stackoverflow.com/questions/855493/referenced-before-assignment-error-in-python) – han solo Sep 20 '19 at 13:14
1 Answers
1
You need to refer to the variable as global inside your function, or it will assume it's local:
def fun():
global win
win+=1

Jonas Byström
- 25,316
- 23
- 100
- 147