简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM