Question: This is a question about global variables, local variables and parameters. Consider the following program: n = int(input()) def add_one(n): return n + 1 def

This is a question about global variables, local variables and parameters.

Consider the following program:

n = int(input()) def add_one(n): return n + 1 def add_n(to): res = to for i in range(n): res += 1 return res print(add_one(4)) print(add_n(4)) print("The result for", i, "is", res)

Which of the following statements is correct? (There could be more than one correct answer.)

The last two lines of the program print the result twice.
The value of "n" in the add_one function is the same as the number "n" that was entered by the user.
"res" is a global variable.
The value of "n" in the add_one function can be different from the number "n" that was entered by the user.
If the user enters the number 12, the program eventually prints the number 16.
The "n" in "range(n)" is incorrect because "n" is not defined as a formal parameter of the add_n function.
The number stored in "to" is always 4.
The loop variable "i" in the last line of the program is equal to the number "n" entered by the user.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!