簡體   English   中英

我似乎無法准確地得到它,我正在得到階乘,但似乎無法找到一種方法來放入組合公式

[英]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)

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))

輸出:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM