简体   繁体   English

如何打印出一个阶乘数? 我的代码不断打印出太多数字,我不知道为什么?

[英]How do I print out one factorial number? My code keeps printing out too many numbers and I do not know why?

#Python Printing out Factorial number #Python 打印出阶乘数

#Input ask for a number #输入要一个数字

iMax = int(input("What is the number to factorialize: "))

iFactorial = 1
iCount = 1

While loop while 循环

while iCount <= iMax:
iFactorial = iFactorial * iCount
iCount = iCount + 1

Print Factorial打印因子

print("factorial of ", iMax, " is ", iFactorial)

Here you have a better way to compute factorial:在这里你有一个更好的方法来计算阶乘:

num = int(input())
fac = 1

for i in range(1, num + 1):
  fac *= i

print("The factorial of", num, "is", fac)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何让我的字典从我的正则表达式循环中打印出更多的值,而不是只打印最后一个值? - How do I get my dictionary to print out more values from my regex loop instead of printing only the last one? 循环保持打印出相同的结果? (python 3.x)如何在每行上打印具有不同结果的循环? - loop keeps printing out same result? (python 3.x) How do I print a loop with different results on each line? 如何打印两个数字的公因数列表? - How do I print out a list of common factors for two numbers? 当我在Python Tutor上运行该代码时,我的代码始终显示错误:“解压缩太多”。 如何解决此错误? - My code keeps displaying an error when I run it on Python Tutor saying: “Too many to unpack”. How do I fix this error? 我有一个代码,需要以不同的顺序打印出来,但它一直在括号中打印出来 - I have a code and need to print out in put in different order but it keeps printing it out in brackets 打印循环时如何执行0? 我一直在尝试在 python 中打印出阶乘。 我需要在输出中打印 0 - How to execute 0 when printing out the loop? I've been trying to print out the factorial in python. I need 0 to be printed in the output 如何在 python 中打印出电话号码? - How do I print out phone number in python? 我该如何修正我的代码,以便它可以打印出我想要的结果? - How Do I Fix My Code So It Can print() Out The Results I Want? 如何重新启动我的阶乘计算器,以便用户可以找到多个数字的阶乘? - How do I restart my factorial calculator so the user can find the factorial of multiple numbers? 如何在输出中打印出正确的ID - How do i print out the right Id with my output
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM