📜  Python| sympy.nC() 方法

📅  最后修改于: 2022-05-13 01:55:10.516000             🧑  作者: Mango

Python| sympy.nC() 方法

借助sympy.nC()方法,我们可以计算 SymPy 中给定长度的组合数。

示例 #1:

# import sympy 
from sympy import * 
  
items = "abca"
k = 3
print("Value of k = {} and the items are = {}".format(k, items))
   
# Use sympy.nC() method 
combinations = nC(items, k)  
      
print("Combinations : {}".format(combinations))  

输出:

Value of k = 3 and the items are = abca
Combinations : 3

示例 #2:

# import sympy 
from sympy import * 
  
items = [2, 1, 3, 5, 4]
k = 3
print("Value of k = {} and the items are = {}".format(k, items))
   
# Use sympy.nC() method 
combinations = nC(items, k)  
      
print("Combinations : {}".format(combinations))  

输出:

Value of k = 3 and the items are = [2, 1, 3, 5, 4]
Combinations : 10