Question:medium

Predict the output of the following code:
def callon(b=20, a=10):
    b = b + a
    a = b - a
    print(b, "#", a)
    return b

x = 100
y = 200
x = callon(x, y)
print(x, "@", y)
y = callon(y)
print(x, "@", y)
    

Show Hint

Understand the sequence of operations and how variables are updated during function calls to accurately predict the output of a Python program.
Updated On: Jan 13, 2026
Show Solution

Solution and Explanation

Initial state: x = 100, y = 200.

Call 1: callon(100, 200)
  b = 100 + 200 = 300
  a = 300 - 200 = 100
  Print: 300 # 100
  Return: 300
  Update x to 300.

Print: x, "@", y → 300 @ 200

Call 2: callon(200) (default a = 10)
  b = 200 + 10 = 210
  a = 210 - 10 = 200
  Print: 210 # 200
  Return: 210
  Update y to 210.

Print: x, "@", y → 300 @ 210

Final Output:
300 # 100
300 @ 200
210 # 200
300 @ 210
    
Explanation: The function callon accepts two parameters, b and a, with default values of b=20 and a=10. Function logic: - b is updated: b = b + a. - a is updated: a = b - a. - The current values of b and a are printed, separated by "#". - The updated value of b is returned. The initial call to callon modifies the variable x. The second call modifies y. The concluding output reflects the state of x and y after these operations.
Was this answer helpful?
0

Top Questions on Commands and Requests