Why do I get a “referenced before assignment” error when assigning to a global variable in a function?
I think you are using ‘global’ incorrectly. See Python reference. You should declare variable without global and then inside the function when you want to access global variable you declare it global yourvar. See this example: Because doA() does not modify the global total the output is 1 not 11.