Write a Python program to display Factorial of a given number by user.
Answers
Required Answer:-
Question:
- Write a Python program to display the factorial of a given number entered by the user.
Program:
This is an easy question. Read this post to get your answer.
Here comes the python program.
This can be done in two ways.
1. Using Loop:
# Written by @_mr_anindya_adhikari_
# Python program to find factorial of a number.
# take a number as input
n=int(input("Enter an integer number: "))
# Checking if number is negative.
if(n<0):
print("Invalid Input. Please try again layer")
else:
# Calculate Factorial
x=1
for i in range(1,n+1):
x*=i;
print("Factorial of the number is: ",x)
2. Without using Loop:
In this approach, we shall use math.factorial() function to find factorial of the number.
Note:- Factorial of any negative number or a decimal will give error.
Here is the program.
# Written by @_mr_anindya_adhikari_
# Python program to find factorial of a number.
# import math
import math
# take a number as input
n=int(input("Enter an integer number: "))
# Checking if number is negative.
if(n<0):
print("Invalid Input. Please try again layer")
else:
#now display the factorial
print("Factorial of the number is: ",math.factorial(n))
Output is attached.
![](https://hi-static.z-dn.net/files/d27/62827be1a187a7d1a6f434021c26671d.jpg)
Answer:
Heya mate here's the answer Mark as brainliest pleaseeeeee follow up
![](https://hi-static.z-dn.net/files/dc2/235c0a0b46a612f7574d9593a5e51376.jpg)
![](https://hi-static.z-dn.net/files/dd9/e12dc7308ca079be15e2284b7fd50f8b.jpg)
![](https://hi-static.z-dn.net/files/d1f/25e12266f95fff9be7fb107ca6b4f03b.jpg)
![](https://hi-static.z-dn.net/files/d9c/39b9624c46930c307bb8d5144a8892e0.jpg)