[英]i can not seem to get it exactly, i am getting the factorials but cant seem to find a way to put in the combination formula
i have written the code but am not able to get the formula of combination to go in, i am very new to this and use these extra excercises to help with math, can you help what to improve or how to complete?我已经编写了代码,但无法获得组合公式,我对此很陌生,并使用这些额外的练习来帮助数学,您能帮助改进什么或如何完成吗?
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)
https://i.stack.imgur.com/SGEDb.png https://i.stack.imgur.com/SGEDb.png
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))
output:输出:
120
126
NOTE: in your formula for mario : n = 10 k = 3, for luigi: n = 9 k = 4注意:在你的马里奥公式中:n = 10 k = 3,对于路易吉:n = 9 k = 4
Taken from https://www.geeksforgeeks.org/factorial-in-python/摘自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)
Or use the maths module:或者使用数学模块:
import math
print (math.factorial(23))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.