ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
import itertools
print(sum(1 for t in itertools.product('01', repeat=10) if t.count('1') == 3))
  1. A. 45
  2. B. 240
  3. C. 120
  4. D. 210

Correct answer: C. 120

Choosing which 3 of the 10 positions hold a 1 gives C(10, 3) = 120. Counting by the 10 positions alone or by pairs of ones would be the usual wrong reasoning.

More Python Programming questions

Exams that ask this topic