Ask coding questions

← Back to all posts
function errors
JeremyIrwin (44)

near the end, it says fighting isn't defined (even though it is in a previous function), how do I link the two together?
and is there something else that I'm doing wrong on this?
sorry, thanks!

Answered by Coder100 (18930) [earned 5 cycles]
View Answer
Coder100 (18930)

Use global to define variables outside of their function, like this:

def fun():
  global fighting
  fighting = True

print(fighting) # no error!