Consider the following Python code. A, B = 10, 5 def FUN(B = 10): global A A…

2026

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

  1. A.

    5 10 0 10 5

  2. B.

    5 15 0 10 5

  3. C.

    5 10 0 15 5

  4. D.

    5 15 0 15 5

Attempted by 58 students.

Show answer & explanation

Correct answer: D

Initial values: A=10, B=5.
First call FUN(A) passes 10 to local parameter B.
Global A becomes 5, local B becomes 15. Output: '5 15'.
Second call FUN() uses default B=10.
Global A becomes 0, local B becomes 15.
Output: '0 15'.
Final print(B) prints global B which is still 5.
Total output: '5 15 0 15 5'.

Explore the full course: Rssb Senior Computer Instructor