What will the following program display?
def main():
x = 1
y = 3.4
print(x, y)
change_us(x, y)
print(x, y)
def change_us(a, b):
a = 0
b = 0
print(a, b)
main()
The following output is generated when the given code is executed:
1 3.4
0 0
1 3.4
The line
1 3.4
will display when the statement print(x,y) is executed
The variables x and y are initialised with values of 1 and 3.4, respectively, in the main() function. Printing the initial values is 1 3.4.
The line
0 0
will display
With the inputs x and y, the change_us() method is called. It's crucial to remember that the function's arguments a and b are independent variables that initially only get the values of x and y.
The variable X and Y in the main() function are unaffected by changes to a and b within the function.
The values 0 are given to variables a and b inside the change_us() function. The function prints the modified values as follows: 0 0.
The line
1 3.4
will display after the change_us() function call, the program returns to the main() function. The values of x and y remain unchanged since the modifications made in change_us() did not affect them.
Thus, the original values of x and y are printed again: 1 3.4.