🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Counting: all 10 questions

Quiz: Counting · Question 9 of 10

What does this print? (code)

What does this print?

count = sum(1 for x in range(7) for y in range(7) for z in range(7) if x + y + z == 6)
print(count)
  1. A.21
  2. B.28
  3. C.36
  4. D.84
Answer & explanation

Correct answer: 28

Stars and bars: C(6 + 2, 2) = C(8, 2) = 28 non-negative solutions.

Can you get the rest right without peeking?

Take the timed Quiz: Counting quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →