Find The Factorial Of A Number | Python Program
Well, at first you need to know what is factorial.
The answer is, it is a non-negative integer. It is the product of all positive integers less than or equal to that number for which you ask for factorial. It is denoted by exclamation sign (!).
For example:- 4! = 4x3x2x1 = 24
Now, if you wondering how to do that through a python program than just observer the
example below…
The answer is, it is a non-negative integer. It is the product of all positive integers less than or equal to that number for which you ask for factorial. It is denoted by exclamation sign (!).
For example:- 4! = 4x3x2x1 = 24
Now, if you wondering how to do that through a python program than just observer the
example below…
Code :
num = int(input("Enter a number: "))
factorial = 1
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",str(num),"is",factorial)
Comments
Post a Comment
Give your feedback!
DO NOT SPAM !!
NO THIRD PARTY PROMOTIONAL LINK !!!! (else comment will be deleted.)