Consider the following Python code. X, Y = 5, 7 def FUN(Y=10): global X X -= Y…

2026

Consider the following Python code.
X, Y = 5, 7
def FUN(Y=10):
global X
X -= Y
Y += X
print(X, Y, end=' ')
FUN(X)
print(Y)
Which of the following is the correct output of this program?

  1. A.

    -2 3 7

  2. B.

    0 5 7

  3. C.

    -5 5 7

  4. D.

    3 -2 7

Attempted by 408 students.

Show answer & explanation

Correct answer: B

Initial values:
X = 5, Y = 7

Function call:
FUN(X) → FUN(5), so parameter Y = 5

Inside function:
global X → refers to global X

Step 1: X -= Y → X = 5 - 5 = 0
Step 2: Y += X → Y = 5 + 0 = 5

print(X, Y) → prints: 0 5

Back to main:
print(Y) → global Y is still 7

Final output:
0 5 7

Explore the full course: Rssb Senior Computer Instructor