Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Local variable 'tools' referenced before assignment

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading