TutorialStudyMite

Factorial Program in Python

HHimani Kohli1 min read
Beginner friendly

Track completion, mastery, and revision.

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:

  1. Input the number from user.
  2. Initialise the product variable to 1.
  3. Use the for loop ranging from 1 till n+1 in order to multiply and find the factorial.
  4. Print the factorial of the number.
  5. 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

Finished reading?

Was this helpful?

Your feedback shapes better tutorials for everyone.