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:
Would you like to see your article here on tutorialsinhand.
program by tutorialsinhand.com
About the Author
Full Stack Web Developer & Blockchain Enthusiast
Page Views :
Published Date :