I have a loop that every 1 second calls a def() with a function that has an if statement, so I need that if that statement is true, to only execute it once, So I thought to multiply the variable so the if statment isn't true again, but I have an error.
i = 0
x = 0
def test():
if i > x:
print("i > x")
x = i * 10
while 1:
test()
time.sleep(1)
Traceback (most recent call last):
File "stackoverflow.py", line 14, in <module>
dynamicStopLoss()
File "stackoverflow.py", line 7, in dynamicStopLoss
if i > x:
UnboundLocalError: local variable 'x' referenced before assignment