← Back to Recursion
Question 614
Binomial By Recursion
Binomial By Recursion
Write choose(n: int, k: int) -> int that returns the number of ways to pick k items out of n, using Pascal's rule by recursion: when k is 0 or k equals n there is exactly 1 way; otherwise the count is choose(n - 1, k - 1) (the ways that include one particular item) plus choose(n - 1, k) (the ways that leave it out). The tests keep n at 12 or below. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: two lines, n then k, no prompts, which the tests read and pass to your function before printing the value it returns.
Expected Output:
10= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
Recursion
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.