Python program to find the factorial of a number
Factorial number of a number is a product from 1 to the number which is from 1 to n where n is the number
Example : factorial of 5 = 1*2*3*4*5 = 120
Code:
#function to find factorial number
def facto(n):
factorial = 1
for i in range(1,n+1):
factorial = factorial * i
return factorial
#Take the input from the user and store in n
n = int(input())
if n == 0: #factorial of 0 is always 1
print(1)
else:
print(facto(n))
#other than 0 we have to find the factorial number by calling the function
Input : 5
Output : 120
There is another method to find factorial number using recursion.
Feel free to check the code in a code editor and try it out and also i am welcome to any suggestion.
Here is the previous post : https://shotwithcode.blogspot.com/2020/12/python-automation-with-selenium.html
Reach through my instagram : https://www.instagram.com/shotwithcode/
Comments
Post a Comment