ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
x = 0
for i in range(1, 101):
    x += i
print(x, x // 2 * 2 == x, x % 2)
  1. A. 5050 True 0
  2. B. 5050 False 0
  3. C. 5050 True 1
  4. D. 5151 True 0

Correct answer: A. 5050 True 0

The sum 1 + 2 + ... + 100 is 5050, which is even, so halving and doubling returns it exactly and the remainder is 0.

More Python Programming questions

Exams that ask this topic