Python Programming
Factorial
Python program for calculating factorial from user given number
By Geekboots
7/22/2021
0 views
factorial.pyPython
#!/usr/bin/evn python
# Take input from the user
num = int(input("Enter a number to calculate factorial: "))
factorial = 1
# Check if the number is negative, positive or zero
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
# For loop iterating by sequence index
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
#***** Output *****
# Enter a number to calculate factorial: 5
# The factorial of 5 is 120
PythonFactorialfactorial calculation