Well, the interpreter is not wrong. There is indeed no local variable named SIN_COUNTER
, only a global one. You have to explicitly declare within the function’s context that the symbol SIN_COUNTER
refers to a global object:
SIN_COUNTER = 0
def update():
global SIN_COUNTER
SIN_COUNTER += 8
SIN_COUNTER = math.sin(SIN_COUNTER)
0
solved Python says a variable is undefined even though it’s clearly defined