17+ Python Factorial Calculator Examples

This post contains a total of 17+ Hand-Picked Python Factorial Calculator Examples with Source Code. All the Factorial Calculators are made using Python Programming language.

You can use the source code of these programs for educational purpose with credits to the original owner.

Related Posts

Click a Code to Copy it.

1. By Aman Yadav

Made by Aman Yadav. Python program to get the factorial of a number. ( Source )

def factorial(n):
  if n <= 1:
    return 1
  else:
    return n * factorial(n - 1)
    
print("_____FACTORIAL CALCULATOR_____")   
print() 
while True:
  x = int(input("Enter the number - "))
  print()
  print("Factorial of ", x , "=")
  print()
  print(factorial(x))  
  print()  
    

2. By Tomiwa Joseph

Made by Tomiwa Joseph. Simple program to calculate the factorial of any number. ( Source )


num = int(input())

def find_factorial(number):
    factorial = 1
    if num < 0:
        print("Come on! Be serious.")
    elif num == 0:
        print("The factorial of 0 is 1.")
    else:
        for i in range(1, num + 1):
            factorial = factorial * i
        print("The factorial of " + str(num) + " is " + str(factorial) + ".")

find_factorial(num)

3. By Edvards

Made by Edvards. Enter a number and it will calculate its factorial. Don’t need the exclamation mark. Enter 52 and find out how many ways there are to arrange a deck of cards. ( Source )

Coefficient = 1
Coefficient_2 = 1
User_input = int(input())
print("Entered number: "+str(User_input)+"!")
while 1==1:
    if Coefficient>User_input:
        break
    Coefficient_2=Coefficient*Coefficient_2
    Coefficient=Coefficient+1
print("Result: "+str(Coefficient_2))

4. By Duc Van Khanh Tran

Made by Duc Van Khanh Tran. ( Source )

def factorial(a):
	for i in range (a):
		if i != 0:
			a = a*i
	return a
b = int(input())#enter an integer
print (factorial (b))

5. By Ratul HasanπŸ‡§πŸ‡©

Made by Ratul HasanπŸ‡§πŸ‡©. Python program to find the factorial of a number provided by the user. ( Source )


# change the value for a different result

num = int(input("Enter a number: "))


factorial = 1

# check if the number is negative, positive or zero
if num < 0:
   print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
   print("The factorial of 0 is 1")
else:
   for i in range(1,num + 1):
       factorial = factorial*i
   print("The factorial of",num,"is",factorial)

6. By UrBoyO

Made by UrBoyO. ( Source )

def factorial(num):
    if num == 0:
        return 1
    else:
        return num * factorial(num - 1)

num = int(input())
print(factorial(num))

7. By Pavitra Golchha

Made by Pavitra Golchha. ( Source )


n=int(input("Input your number: "))
print(str(n) + "!")
total = 1

if n > 1:
    for i in range(1,n):
        total *= (i+1)
    print("-"*40)
    print("The answer is " + str(total))
elif n < 0:
    print("-"*40)
    print("[Error] Enter positive numbers only!")
else:
    print("-"*40)
    print("The answer is " + str(total))

8. By TheLegend27

Made by TheLegend27. ( Source )


x = input()
lis = list(range(1,(int(x)+1)))
a = (len(lis))
c = a - 1
b = 1
for i in lis:
  b = b*lis[c]
  c = c - 1
answer = "{e}! is equall to: {j}". format(e = x, j = b)
print (answer)

9. By Caleb Hale

Made by Caleb Hale. ( Source )

print ("welcome to the factorial calculator!")
x = input("enter (whole positive) number:")
numselect = x
solution = 1
while not numselect == 1:
    solution = solution * numselect
    numselect -= 1

print ("The factorial of" + x + "is" + solution)

10. By Minenhle Simphiwe

Made by Minenhle Simphiwe. ( Source )

n =int(input(""))
def factorial(n):
    if n==0:
      return 1
    else:
      return n*factorial(n-1)
print(factorial(n))

11. By Zach

Made by Zach. ( Source )

# INPUT YOUR FAVORITE NUMBER THEN PRESS ENTER. INPUT 1 FOR PRODUCT FACTORIAL OR 0 FOR SUM FACTORIAL
num = int(input("What's your favorite number? "))
print("\nSo your favorite number is " + str(num) + ", eh?\nI shall figure out the product or sum factorial: your choice human")
choice = int(input("Input 1 for product factorial or 0 for sum factorial. Do not dare input anything else."))
print("\nLet me work my computer magic\nBoop boop beep boop crrrrrsssshhhhhhhhhrrrrrsssssaaaaahhhhh\nPerforming computer magic for you, humanoid servant")
prod = 1
summ = 0
numlist = list(range(num+1))
if choice ==1: #they want a product factorial
    for i in numlist:
        if i>0:
            prod *= i
    print("The product factorial of " + str(num) + " is " + str(prod))
elif choice == 0: #they want a sum factorial
    for i in numlist:
        prod += i
    print("The sum factorial of " + str(num) + " is " + str(summ))
else: #they don't know how to click 1 or 0..
    print("What")

12. By Coffee4Cup

Made by Coffee4Cup. ( Source )

n = int(input())
result = 1
while n > 1:
   result *= n
   n -= 1
print(result)

13. By Utkarsh Prajapati

Made by Utkarsh Prajapati. A small python program to find the factorial of a number. ( Source )

n=1
for i in range(int(input())):
    n*=i+1
print(n)

14. By Poduru Shesha Sai

Made by Poduru Shesha Sai. ( Source )

number=int(input())
print("Enter a number",number)
factorial=1
if number<0:
    print("Factorial for a Negative Numbers Doesn't Exist")
elif number==0:
    print("The Factorial of 0 is '1'")
else:
    for i in range(1,number+1):
        factorial=factorial*i
    print("The Factorial of",number,"is",factorial)

15. By Franco Basilone

Made by Franco Basilone. This code is able to calculate the factorial of any number lesser than 25195, it may change depending on the device. ( Source )


import math

num = int(input()) 
fact = math.factorial(num)

print(f"Factorial of {num} is: {fact}\n\nIt has {len(str(fact))} digits")

16. By Christian

Made by Christian. ( Source )

x = int(input())


def fact(x):
    if x == 0:
        return 0
    if x == 1:
        return 1
    else:
        return x * fact(x-1)

print('{}! = {}'.format(x, fact(x)))

17. By ezman 69420

Made by ezman 69420. Basic python program to get the factorial of a number. ( Source )

y = input("Enter the number to take the factorial of:")
print ("\nYour number is" + ": " + y)
x = int(y)
def factorial(n):
    if n == 1:
      return 1
    return n * factorial(n-1)
print("Your number's factorial is: " + str(factorial(x)))

18. By Conan Tan

Made by Conan Tan. Find out the factorial of the number you put in the input box! ( Source )


x=int(input(""))
fact=1
if x<0:
 print("Negative numbers do not have a factorial.")
elif x == 0:
  print("The factorial of 0 is 1")
else:
  for i in range(1,x+1):
     fact *= i
  print("The factorial of %d is %d"%(x,fact))