Jan-09-2020, 03:12 AM
Hi, I'm going through the python in easy steps book and have hit a snag with global/coerced variables.
I've copied the code exactly from the book but not getting the return I expect.
Here is the code:
Global Variable: 1
Local Variable: 2
Coerced Variable 3
Any ideas as I've copied this exactly from the book.
Thanks in advance
I've copied the code exactly from the book but not getting the return I expect.
Here is the code:
global_var = 1
def my_vars():
print( "Global Variable:" , global_var )
local_var = 2
print( "Local Variable:" , local_var )
global inner_var
inner_var = 3
my_vars()
print( "Coerced Global:" , inner_var )This is what I get back when I run it:Error:C:\Users\rev\PycharmProjects\untitled1\venv\Scripts\python.exe C:/MyScripts/scope.py
Process finished with exit code 0What I should be getting back is:Global Variable: 1
Local Variable: 2
Coerced Variable 3
Any ideas as I've copied this exactly from the book.
Thanks in advance
