首页 > 解决方案 > 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

#Input ask for a number

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

iFactorial = 1
iCount = 1

While loop

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

Print Factorial

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

标签: python

解决方案


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)

推荐阅读