ProgrammingModerateGATE CS · Product-company placement

What is printed?

What is printed?
count = 0
for i in range(1, 4):
    for j in range(i):
        if (i + j) % 2:
            continue
        count += 1
print(count, i, j)
  1. A. 3 3 2
  2. B. 2 3 2
  3. C. 2 4 3
  4. D. 2 3 3

Correct answer: B. 2 3 2

Of the pairs (1,0), (2,0), (2,1), (3,0), (3,1), (3,2), only (2,0) and (3,1) have an even sum; continue skips the rest, so count is 2. After the loops, i and j keep their last values 3 and 2.

More Python Programming questions

Exams that ask this topic