ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
x, rev = 1200, 0
while x:
    rev = rev * 10 + x % 10
    x //= 10
print(rev, int(str(1200)[::-1]), str(1200)[::-1] == '0021')
  1. A. 0021 21 True
  2. B. 21 21 False
  3. C. 21 21 True
  4. D. 21 1200 True

Correct answer: C. 21 21 True

The digit loop drops leading zeros naturally, so reversing 1200 gives 21 rather than 0021. The string reversal keeps the zeros, so the string comparison with '0021' is True.

More Python Programming questions

Exams that ask this topic