Factorial of n is the product of all positive descending integers. Factorial of n is denoted by n!.
Here, 4! is pronounced as “4 factorial”, it is also called “4 bang” or “4 shriek”.
The factorial is normally used in Combinations and Permutations (mathematics).
There are many ways to write the factorial program in Python language. Let’s see the 2 ways to write the factorial program in Python.
- Factorial Program using loop
- Factorial Program using recursion
Factorial Using Loop in Python
num = int(input("Enter a number: "))
fact = 1
for i in range(1,num+1):
fact = fact * i
print("Factorial of ",num, "is :",fact)
Factorial Using Recursive Function in Python
# Factorial using Recursion
num = 4