Python Program to find the Factorial of a Number
The factorial of a positive integer n, denoted by n! is the product of all positive integers less than or equal to n.
for example factorial of 6 i.e 6! = (6 * 5 * 4 * 3 * 2 * 1) which is equal to 720
Factorial of the number 0 is 1 ( i.e 0! = 1 )
Source Code for Find the Factorial of a number using Recursive Function
1 # Python program to find the factorial of given number
2
3 #Create a function to find factorial
4 def factorial(n):
5 if (n==1 or n==0):
6 return 1
7 else:
8 return n * factorial(n - 1);
9
10 #call the factorial function to get result
11 num = 6;
12 if(num < 0):
13 print("Cant find the factorial of negative numbers")
14 else:
15 print("Factorial of",num,"is",factorial(num))
Source Code for Find the Factorial of a number using Iterative Process
1 # Python program to find the factorial of given number
2
3 num = int(input("Enter a number to find factorial : "))
4 factorial = 1
5
6 if num < 0:
7 print("Cant find the factorial of negative numbers")
8 elif num == 0:
9 print("The factorial of 0 is 1")
10 else:
11 for i in range(1,num + 1):
12 factorial = factorial*i
13
14 print("The factorial of",num,"is",factorial)