conditions as defined in sect for the local scope the identifier must be defined using id it must be parameter to the enclosing functionor it must be an identifier for class or function definition in the enclosing scope' function on line when python encounters the identifier historyofoutput it finds that identifier defined in the enclosing scope and retrieves it for use in the call to the append method which scope is local depends on where your program is currently executing when executing line the light green region is the local scope when executing line the brown region is the local scope when executing line or line the purple region is the local scope when executing line the darker green region is the local scope finallywhen executing line or the blue region is the local scope the local scope is determined by where your program is currently executing scopes are nested this means that each scope is nested inside another scope the final enclosing scope of module is the module itself each module has its own scope the blue region of fig corresponds to the module scope identifiers that are defined outside of any other functionsbut inside the moduleare at the module level the reference pi in fig is defined at the module level the functions area and main are also defined at the module level scope while executing line of the program in fig the identifier val is defined in the local scope butval is also defined in the enclosing scope this is acceptable and often happens in python programs each scope has its own copy of identifiers the choice of which val is visible is made by always selecting the innermost scope that defines the identifier while executing line of the program in fig the val in the local scope is visible and the val in the enclosing scope is hidden this is why it is important that we choose our variable names and identifiers carefully in our programs if we use an identifier that is already defined in an outer scopewe will no longer be able to access it from an inner scope where the same identifier is defined it is relatively easy to determine all the nested scopes within module every function definition (including the definition of methodswithin module defines different scope the scope never includes the function name itselfbut includes its parameters and the body of the function you can follow this pattern to mentally draw boxes around any scope so you know where it begins and ends in your code global scope using python it is possible to define variables at the global level generally this is bad programming practice and we will not do this in this text if interested you can read more about global variables in python online butusing too many global variables will generally lead to name conflicts and will likely lead to unwanted side effects poor use of global variables contributes to spaghetti code which is named for the big mess you would have trying to untangle it to figure out what it does this copy belongs to 'acha