Find the total number of possibilities to choose k things from n items:
# Import math Library
import math
# Initialize the number of items to choose from
n = 7
# Initialize the number of possibilities to choose
k = 5
# Print total number of possible combinations
print (math.comb(n, k))
The result will be:
21
The math.comb()
method returns the number of ways picking k unordered outcomes from n possibilities, without repetition, also known as combinations.
Note: The parameters passed in this method must be positive integers.
Syntax Parameter Values Parameter Description n Required. Positive integers of items to choose from k Required. Positive integers of items to chooseNote: If the value of k is greater than the value of n it will return 0 as a result.
Note: If the parameters are negative, a ValueError occurs. If the parameters are not integers, a TypeError occurs.
Technical Details Return Value: Anint
value, representing the total number of combinations Python Version: 3.8
Track your progress - it's free!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4