The in-built math.comb()
function from the math
module in Python
is used to find the total number of unordered combinations to choose k amount of items from n items.
math.comb(n,k)
This function
requires two positive integers, n and k, as parameters.
If the passed parameters are negative, aValueError
arises. If the parameters are not integers, a TypeError
arises.
If k > n, 0
is returned.
import mathpeople = 6chairs = 3# Number of possible combinations of 6 different people# being seated in 3 chairsprint(math.comb(people, chairs))
import mathpeople = 6chairs = 7# Return value is 0 when# k(number ofchairs) > n(number of people)print(math.comb(people, chairs))