找回密碼
 註冊
搜索
查看: 937|回復: 0

[教學] Python math.comb() 如何算出來

[複製鏈接]
發表於 2021-1-7 15:02:41 | 顯示全部樓層 |閱讀模式
 
Push to Facebook
就是高中數學的那個排列組合的組合,C。從 n 樣東西里,取出 m 樣,計算有幾種取法
就是那個組合的 nCm
公式寫出來就是 n!/( (n-m)!*m! )
  1. # Import math Library
  2. import math

  3. # Initialize the number of items to choose from
  4. n = 7

  5. # Initialize the number of possibilities to choose
  6. k = 5

  7. # Print total number of possible combinations
  8. print (math.comb(n, k))
複製代碼
The result will be:

21

 
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

Archiver|手機版|小黑屋|TShopping

GMT+8, 2025-7-6 06:20 , Processed in 0.024869 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回復 返回頂部 返回列表