ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(sum(bin(i).count('1') for i in range(8)))
  1. A. 8
  2. B. 10
  3. C. 12
  4. D. 9

Correct answer: C. 12

The bit counts for 0 to 7 are 0, 1, 1, 2, 1, 2, 2, 3. Their sum is 12.

More Python Programming questions

Exams that ask this topic