Example 1: Define a function that takes an argument. Call the function. Identify what code is the argument and what code is the parameter. Example 2: Call your function from Example 1 three times with different kinds of arguments: a value, a variable, and an expression. Identify which kind of argument is which. Example 3: Construct a function with a local variable. Show what happens when you try to use that variable outside the function. Explain the results.
Example 1: Define a function that takes an argument. Call the function. Identify what code is the argument and what code is the parameter.
Example 2: Call your function from Example 1 three times with different kinds of arguments: a value, a variable, and an expression. Identify which kind of argument is which.
Example 3: Construct a function with a local variable. Show what happens when you try to use that variable outside the function. Explain the results.
Example 4: 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.
Example 5: 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.
The code and its output must be explained technically whenever asked. The explanation can be provided before or after the code, or in the form of code comments within the code. For any descriptive type question, Your answer must be at least 150 words.
End your discussion post with one question related to
“Since you have posted a question with multiple sub-parts, we will solve the first three sub-parts for you. To get the remaining sub-part solved please repost the complete question and mention the sub-parts to be solved.”
Example 1:
Algorithm steps for the given problem:
- Start
- Define a function printFunction(n1, n2)
- Declare a variable n3 and set it equal to n1 + n2 # 3. Return the value of n3
- Call the function printFunction(2, 3)
- Print the value of x which is the return value of printFunction(2, 3)
- Stop.
Trending now
This is a popular solution!
Step by step
Solved in 9 steps with 6 images