-
Code from math import factorial def get_combination(k: int, n: int) -> int: 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 factorial(n) / (factorial(n-k)*factorial(k))
Test Cases import codewars_test as test from solution import get_combination .describe("Example") def test_group(): .it("test case") def test_case(): test.assert_equals(get_combination(1, 13), 13.0) test.assert_equals(get_combination(7, 76), 2186189400.0) test.assert_equals(get_combination(7, 5), "n must be greater than or equal to k.") test.assert_equals(get_combination(-1, 5), "n and k must be positive.") test.assert_equals(get_combination(9, 15), 5005.0) test.assert_equals(get_combination(45, 201), 1.773741968572955e+45)
Output:
-
Code def get_combination(k, n):def fact(x):res = 1for i in range(1,x+1): res*=ireturn res- from math import factorial
- def get_combination(k: int, n: int) -> int:
- 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))- return factorial(n) / (factorial(n-k)*factorial(k))
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}