firstCall = False
def buttonDown():
if firstCall == True:
print("Initial Call")
firstCall = False
else:
print("Subsequent Call")
def buttonUp():
firstCall = True
buttonDown()
buttonDown()
buttonDown()
I think this code translated would run in C#, but in Python reassigning firstCall to False to stop "Initial Call" from printing again results in an error UnboundLocalError: local variable 'firstCall' referenced before assignment
How should this logic be written?
I expected the output to be:
Initial Call Subsequent Call Subsequent Call
Instead I get an compile error. Commenting out the line that causes the error, firstCall = False, results in, of course:
Initial Call Initial Call Initial Call