Python Program to Find the Factorial of a Number

By | October 3, 2021
Python Program to Find the Factorial of a Number

In this python tutorial, you will learn how to write a Python program to calculate the factorial of a number.

Prerequisite topics to create this program.

Steps

  • First, we will ask the user to enter a number
  • Using the int() function we will convert the entered number into an integer value.
  • Using the for loop we will go through each value from 1 to the entered number and multiply each one.

Python Program to Find the Factorial of a Number:

Code:

num =int(input("Enter a Number: "))
fact=1
for i in range(1,num+1):
    fact*=i
if num==0:
    print("The factorial is 1")
else:
    print("The factorial of",num,"is",fact)

Output 1:

Enter a Number: 12
The factorial of 12 is 479001600

Output 2:

Enter a Number: 5
The factorial of 5 is 120

People are also reading:

Author: Vinay Singh

I am a Full Stack Developer with a Bachelor's Degree in Computer Science, who also loves to write technical articles that can help fellow developers.

Leave a Reply

Your email address will not be published.