Construct a function that takes an argument. Give the function parameter a unique name. Show what happens when you try to use that parameter name outside the function. Explain the results. Show what happens when a variable defined outside a function has the same name as a local variable inside a function. Explain what happens to the value of each variable as the program runs.
# Python 3
def printFunction(num1, num2):
num3 = num1 + num2
return num3
print(num3)
Explanation: Here, num3 is the local variable that is defined in the scope of the function and when it is used outside the function, an error occurs. Print(num3) is the statement which is outside the scope of the function. So, when this statement is executed, there is no variable named num3 to be printed, so it gives an error.
The error that occurs is : NameError: name 'num3' is not defined
Construct a function that takes an argument. Give the function parameter a unique name. Show what happens when you try to use that parameter name outside the function. Explain the results.
Show what happens when a variable defined outside a function has the same name as a local variable inside a function. Explain what happens to the value of each variable as the
Python:
Python is a general purpose, high level programming language.
It uses indentation instead of curly braces.
It has simple syntax and dynamic semantics.
It supports both procedural and object oriented programming approaches.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 4 images