ProgrammingHardTCS CodeVita · Infosys HackWithInfy · Product Company SDE

What does the following Python 3 code print? print(sum(x * x for x in range(30) if x % 4 == 1))

  1. A. 2472
  2. B. 14400
  3. C. 6083
  4. D. 1820

Correct answer: A. 2472

The generator squares each x in range(n) (stop exclusive) that satisfies the filter, then sum adds them. Output: 2472.

More Python Programming questions

Exams that ask this topic