Factorial of a Number in Python.
number = int(input("Enter a number :: "))
fact = 1
if number < 0:
print("Factorial does not exist for negative numbers")
elif number == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,number + 1):
fact = fact*i
print("The factorial of",number,"is",fact)
OUTPUT
Enter a number :: 5
The factorial of 5 is 120
No comments:
Post a Comment
Please do not any spam link in Comment Box