I don't know why when a
is located in def test()
it can not be found and gives the error
UnboundLocalError: cannot access local variable 'a' where it is not associated with a value
import keyboard
import time
a = 0
def test():
a+= 1
print("The number is now ", a)
time.sleep(1)
while keyboard.is_pressed('i') == False:
test()
I tried setting a
as global a
or using a nonlocal
modifier on it inside the def
but it doesn't seem to work. Is there a way I can get it to recognize a
and run properly?