用python 写 组合数C(m,n)=m!/n!/(m-n)!。试编写阶乘的函数及组合数的函数?

如题所述

import math
m = int(input("请输入第一个数字:"))
n = int(input("请输入第二个数字:"))
if m < 0 or n < 0 or m - n < 0:
print("负数是没有阶乘,请重新输入!")
else:
result = math.factorial(m) / math.factorial(n) / math.factorial(m - n)
print("按照公式C(m, n) = m!/n! /(m - n)!,C({0},{1})的答案为 {2}".format(m, n, result))
温馨提示:答案为网友推荐,仅供参考
相似回答