removed recursion in factorial function
def get_combination(k, n): def fact(x): res = 1 for i in range(1,x+1): res*=i return res if k <= 0 or n <= 0: return "n and k must be positive." if n < k: return "n must be greater than or equal to k." return fact(n) / (fact(n-k)*fact(k))
- def get_combination(k, n):
def get_factorial(x):if x <= 0:return Noneif x <= 1:return 1return x * get_factorial(x-1)- def fact(x):
- res = 1
- for i in range(1,x+1): res*=i
- return res
- if k <= 0 or n <= 0:
- return "n and k must be positive."
- if n < k:
- return "n must be greater than or equal to k."
else:combination = get_factorial(n) / (get_factorial(n-k)*get_factorial(k))return combination- return fact(n) / (fact(n-k)*fact(k))