我已经编写了代码,但无法获得组合公式,对此我很陌生,可以使用这些额外的练习来帮助数学,您能帮忙改进或完成什么吗? / p>
n=(10)
fact=3
while(n>0):
fact=fact*n
n=n-1
print("Factorial of the number is: ")
print(fact)
n=int(6)
fact=1
while(n>0):
fact=fact*n
n=n-1
print("Factorial of the number is: ")
print(fact)
答案 0 :(得分:0)
def fact_(n):
fact = 1
while (n > 0):
fact = fact * n
n = n - 1
return fact
#mario
result_m = fact_(10)/(fact_(3)*fact_(7))
print(int(result_m))
#luigi
result_l = fact_(9)/(fact_(4)*fact_(5))
print(int(result_l))
输出:
120
126
注意:在您的马里奥公式中:n = 10 k = 3,对于路易基犬:n = 9 k = 4
答案 1 :(得分:-1)
来自https://www.geeksforgeeks.org/factorial-in-python/
n = 23
fact = 1
for i in range(1,n+1):
fact = fact * i
print ("The factorial of 23 is : ",end="")
print (fact)
或使用maths模块:
import math
print (math.factorial(23))