"""组合数""" def zuhe(m,n): c = 1 b = 1 d = 1 num2 = 1 num1 = 1 num3 = 1 while c <= m: if c <= m: num1 = num1 * c c = c +1 while b <= n: if b <= n: num2 = num2 * b b = b + 1 while d <= m-n: if d <= m-n: num3 = num3 * d d = d + 1 print(num1,num2,num3) num = int(num1 /(num2*num3)) print(num) return num zuhe(11,9) """排列数""" def pailei(m,n): c = 1 b = 1 num2 = 1 num1 = 1 while c <= m-n: if c <= m-n: num1 = num1*c c = c + 1 while b <= m: if b <= m: num2 = num2*b b = b + 1 print(num2,num1) num = int(num2/num1) print(num) return num pailei(9,2)
python中实现组合数和排列数
最新推荐文章于 2024-06-07 13:28:03 发布