ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
import itertools
print(len(list(itertools.combinations_with_replacement(range(5), 3))))
  1. A. 125
  2. B. 35
  3. C. 60
  4. D. 10

Correct answer: B. 35

combinations_with_replacement of n items taken r at a time has C(n + r - 1, r) results. Here C(7, 3) = 35. Plain combinations would give C(5, 3) = 10, and product would give 125.

More Python Programming questions

Exams that ask this topic