2019-07-02 04:05:43 +00:00
|
|
|
"""Python program to find the factorial of a number provided by the user."""
|
2018-10-31 07:28:41 +00:00
|
|
|
|
|
|
|
# change the value for a different result
|
2019-07-02 04:05:43 +00:00
|
|
|
NUM = 10
|
2018-10-31 07:28:41 +00:00
|
|
|
|
|
|
|
# uncomment to take input from the user
|
2019-07-02 04:05:43 +00:00
|
|
|
# num = int(input("Enter a number: "))
|
2018-10-31 07:28:41 +00:00
|
|
|
|
2019-07-02 04:05:43 +00:00
|
|
|
FACTORIAL = 1
|
2018-10-31 07:28:41 +00:00
|
|
|
|
|
|
|
# check if the number is negative, positive or zero
|
2019-07-02 04:05:43 +00:00
|
|
|
if NUM < 0:
|
|
|
|
print("Sorry, factorial does not exist for negative numbers")
|
|
|
|
elif NUM == 0:
|
|
|
|
print("The factorial of 0 is 1")
|
2018-10-31 07:28:41 +00:00
|
|
|
else:
|
2019-07-02 04:05:43 +00:00
|
|
|
for i in range(1, NUM + 1):
|
|
|
|
FACTORIAL = FACTORIAL * i
|
|
|
|
print("The factorial of", NUM, "is", FACTORIAL)
|