Work out yourself in three ways, and check that they agree with Python's math.comb.
The idea. The formula is . It is quicker to multiply fractions: . Listing the selections with itertools.combinations checks both.
Your tasks.
factorial, return with a loop. Remember .choose, return , using your factorial.choose_fast, multiply step by step: start with c = 1, and for k from 1 to r, set c = c * (n - r + k) // k.count_list, return how many selections of r items itertools.combinations makes from range(n).Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…
With Standard, you also open 12 more problems, 2 Python labs and 1 extra course. Everything you have used here stays free, always.