Python Program to find the Factorial of a number

Find a Factorial of a Number

In this Python Program, We will find the factorial of a number where the number should be entered by the user. Factorial of a number means multiply of all below number with each other till 1. If user enter 0 or 1 , then factorial of both numbers will be 1 only. Or If user enters negative numbers then it’s factorial is not defined.
For Example:
Number is 8.
Factorial of a 8 = 40,320
Note:-Factorial of n number is 1*2*3*…n. You will learn to calculate the factorial of a number using for loop in this example.
Python Program to find the Factorial of a number


Step 1.Read the number num.

Step 2.Initialize the variable factorial=1

Step 3.To take a user input for factorial of number

Step 4.We use for loop starts from 1 to num + 1.

Step 5.Then, Inside For loop factorial = factorial * i

Step 6.Print the variable of factorial.

Step 7.Stop

Python Program:

num = int(input("Enter the number:"))
factorial = 1
for i in range(1, num+1):
    factorial = factorial * i

print("Factorial of a Given Number:", factorial)

# This code is contributed by Shubhanshu Arya (Prepinsta Placement Cell Student) 


Enter the number:5
Factorial of a Given Number: 120