generate functionTue, 14 Feb 2023

To calculate C(n, k) in other cases, the following recursive formula is used: C(n, k) = C(n - 1, k) + C(n - 1, k - 1). Implement a program that, given n and k, calculates C(n, k). Your program is given a string containing two integers n and k (1 ≤ n ≤ 10, 0 ≤ k ≤ 10) as input. Your program should output a single number: C(n, k). Note: You can count two numbers n and k, for example, as follows: n, k = map(int, input().split())

def comb(n, k): if k > n: return 0 elif k == 0: return 1 else: return comb(n-1, k) + comb(n-1, k-1) n, k = map(int, input().split()) result = comb(n, k) print(result)

Questions about programming?Chat with your personal AI assistant