简体   繁体   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

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.

相关问题 我该如何解决这个我似乎找不到的缩进错误? - How can i fix this Indentation Error I cant seem to find? 我有办法重写代码吗?,我似乎无法正确执行,我似乎无法正确获取输入 - i there a way to rewrite the code?,i can not seem to get it right, i can not seem to get the input correctly 我是新手,尝试掷 3d6,重新掷 1,然后将它们放入列表中。 我似乎无法在列表中获得 3 个“新”值。 数字不断增加 - I am new, trying to roll 3d6, rerolling 1's, and put them into a list. I cant seem to get 3 "new" values in the list. The numbers just keep adding up 我正在尝试获取 pyqt 所以我可以获取 pylint 但我似乎无法安装它我绝对是 python 和编码的菜鸟 - I'm trying to get pyqt so i can get pylint but i cant seem to install it i am a absolute noob to python and coding in general 我究竟做错了什么? 似乎无法将参数传递给服务器 - what am i doing wrong? cant seem to pass a parameter to server 我似乎陷入了无法脱身的困境 - I seem to be in a predicament where I cant get out of the loop 我正在尝试编写一个“机器人”服务员程序,但我似乎找不到我出错的地方 - I am trying to program a "robot" waiter program but I can't seem to find where I went wrong 我正在尝试使用 selenium 加载等待列表并单击按钮,但我似乎找不到该元素 - I am trying to use selenium to load a waiting list and click the button, but I can't seem to find the element 我似乎无法摆脱的 tkinter 程序错误 - a tkinter program error i cant seem to get rid of 还有另一种方式可以写这个吗? 我只知道打印功能,但我似乎无法像示例那样得到它 - is there another way i can write this? i only know the print function,but i can not seem to get it like the example
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM