Problem scenario
You have a Python program that works, but you get an error when you run it. You get a message like this: “NameError: global name ‘var2’ is not defined”
Here is your source code:
def fun1(var1):
print(“this is how it works”)
var1 = var2
return var2
b = fun1(“check it out”)
print(b)
What should you do about this error?
Solution
A variable inside a function must be defined.
…