ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
n = 12345
print(n // 10 ** 3 % 10, n % 10 ** 3 // 100, str(n)[1], n // 1000 % 10 == int(str(n)[1]))
  1. A. 2 3 3 True
  2. B. 3 3 2 True
  3. C. 2 3 2 True
  4. D. 2 4 2 False

Correct answer: C. 2 3 2 True

Integer division and modulus can extract digits by position: n // 1000 % 10 is the thousands digit, 2. n % 1000 // 100 is the hundreds digit, 3. The string index gives the same digit as the arithmetic.

More Python Programming questions

Exams that ask this topic