ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(sum(x for x in range(1, 11) if x & 1), sum(x for x in range(1, 11) if x & 2))
  1. A. 30 28
  2. B. 25 18
  3. C. 25 28
  4. D. 25 25

Correct answer: C. 25 28

The odd numbers from 1 to 10 sum to 25. Numbers with the value-2 bit set are 2, 3, 6, 7 and 10, which sum to 28.

More Python Programming questions

Exams that ask this topic