ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
x = 0
def a():
    global x
    x = 1
    def b():
        global x
        x += 10
    b()
    return x
print(a(), x)
  1. A. 1 11
  2. B. 11 11
  3. C. 11 1
  4. D. 1 1

Correct answer: B. 11 11

Both functions declare x global, so they modify the single module-level x: a sets it to 1, b adds 10.

More Python Programming questions

Exams that ask this topic