Articles

Python program to find factorial of a number

Python program to find factorial of a number


In this python programming guide, we will learn to write,

  • simple python program to find factorial of a number

Program to find factorial of a number in Python

The program to find factorial of a number in python is as follows:

 

# Owner : TutorialsInhand Author : Devjeet Roy

n = int(input("Enter number: "))
fact = 1

for i in range(n,0,-1):
    fact *= i

print("The factorial is:",fact)

The output of python program to find factorial of a number is as follows:

 

PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter number: 5
The factorial is: 120

Few important points about this problem:

1. Firstly, we ask theuser to input any number and then we convert to its int equivalent.

2. We initialize the "fact" variable as 1.

3. Then, we start a loop from n and deduce to 1 (as zero is exclusive) and keeping multiplying the numbers with their previous product.

4. Finally, we get the factorial of the number.

 

Snapshot to write a python program to find factorial of a number is given below:

write a python program to find factorial of a number

 


Basic Python Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Devjeet Roy
Full Stack Web Developer & Data Science Enthusiast
Page Views :    Published Date : Feb 14,2021  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!