I understand the concept of local and global variables in Python, but I just have a question about why the error comes out the way it is in the following code. Python execut
Python doesn't execute line by line in the function code you submitted. It has first to parse it as a bloc of execution. It decides if a variable is local or global depending if it is written at (function) local level. As it is the case, it decides that the variable is local, hence the error.