nameerror: name is not defined
the hello() function causes and error becuase 'string' is not defined, although it clearly is defined.
why does this happen and how do i fix it
although it clearly is defined
Actually no, to Python it's not (I know, weird right?). Python requires that you "import" the string into the scope of the function with
global. (EDIT: There's something weird going on... this shouldn't have to be done with Python, but for some reason it's the only thing that works.).
So, you'll want to do this:
string = "hello world" def hello(): global string print(string) hello()