ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: C. 21 2

Python evaluates the left operand f() first (x becomes 1, value 1), then f() * 10 (x becomes 2, value 2 * 10 = 20). The sum is 21, and the global is 2.

More Python Programming questions

Exams that ask this topic