I’m a newbie in python. I’m currently creating a simple program. Can you guys educate me how global keyword works? I ran the code and after typing 3 to select the shutdown option I’m being greeted by local variable ‘tools’ referenced before assignment. It’s been hours and I can’t figure this out. Thanks for the help guys.
This is the error code:
You can see the code here. I don’t want to put the entire code in here because it’s too long.
>Solution :
It’s because, at the very end of the program, you are calling tools(Line 165). However, because tools was defined inside of an if block that wasn’t executed, that function doesn’t exist. What you need to do is move the definition of tools outside of the if-statement to the top level so that it is can be executed anywhere.