[英]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
我已經編寫了代碼,但無法獲得組合公式,我對此很陌生,並使用這些額外的練習來幫助數學,您能幫助改進什么或如何完成嗎?
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)
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
摘自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)
或者使用數學模塊:
import math
print (math.factorial(23))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.