我似乎无法完全得到它,我正在获得阶乘,但似乎找不到找到组合公式的方法

时间:2019-06-19 15:12:28

标签: python python-2.7 function methods

我已经编写了代码,但无法获得组合公式,对此我很陌生,可以使用这些额外的练习来帮助数学,您能帮忙改进或完成什么吗? / 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)

https://i.stack.imgur.com/SGEDb.png

2 个答案:

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