Factorial Program in Python
Written by
Program to find factorial in Python
Here, we are going to learn how to get the factorial of a number and display it.
Factorial of a positive integer is the multiplication of all integers smaller than or equal to n.
It is represented as n*(n-1)*(n-2)………….1
Example: 4! = 4*3*2*1 =24
Algorithm:
- Input the number from user.
- Initialise the product variable to 1.
- Use the for loop ranging from 1 till n+1 in order to multiply and find the factorial.
- Print the factorial of the number.
- Exit
Code:
n= int(input("Enter the number you want to find the factorial of: "))
prod=1
for i in range(1,n+1):
prod=prod*i
print(prod)
Output:
Enter the number you want to find the factorial of: 5
120