I want to run an infinite loop and at every 100th loop i want to print. If I do this : it works perfectly,
delay=0
while 1:
delay=delay+1
print(delay)
if delay>100:
delay=0
print('100th time')
However if I put my if statement in a function it gives error:
delay=0
def foo():
if delay>100:
delay=0
print('100th time')
while 1:
delay=delay+1
print(delay)
foo()
The error is : UnboundLocalError: local variable 'delay' referenced before assignment.
Is there anyway I can do the reassignment in a function? Putting the entire thing in my while loop would be problematic for me.