[英]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 iCount <= iMax:
iFactorial = iFactorial * iCount
iCount = iCount + 1
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.