Identify the output of the following Python code: N1 = 10 def EXP(N2): global…

2023

Identify the output of the following Python code:

N1 = 10
def EXP(N2):
    global N1
    N1, N2 = N1 + 5, N2 + 10
    print(N1, N2, end='')
EXP(N1)
print(N1)

  1. A.

    10 2015

  2. B.

    15 2010

  3. C.

    15 2015

  4. D.

    10 2010

Attempted by 1379 students.

Show answer & explanation

Correct answer: C

Explanation:

  • Initial value: global N1 = 10. The function EXP is called with N2 = 10.

  • Right-hand side is evaluated first: N1 + 5 = 15, N2 + 10 = 20.

  • Assignment: global N1 is set to 15, local N2 is set to 20.

  • The print inside the function uses end='', so it outputs "15 20" without a newline.

  • After the function call, print(N1) outputs "15" immediately after the previous output.

Final output (exact characters printed): 15 2015

Note: The first print uses end='', so there is no space or newline between "20" and the final "15", resulting in "15 2015".

Explore the full course: Rssb Senior Computer Instructor