# Python program to find Factorial of a given number

**What is Factorial of a number ? **

**The Factorial is the product of all integers less then or equal to n but greater than or equal to 1. It is symbolized by an exclamation mark (!).**

**Formula:**

**Python Code:**

__By Using While loop:__

```
n = int(input("Enter a number:"))
p = 1
while n >= 1:
p = p*n
print(n,"x",end=" ")
n -= 1
print("\b\b","=",p)
```

**Output:**

**Enter a number: 4**

**4 x 3 x 2 x 1 = 24**

__By Using For loop:__

```
n = int(input("Enter a number:"))
p = 1
for i in range(n,0,-1):
p = p*i
print(i,"x", end=" ")
print("\b\b", "=", p)
```

**Output:**

**Enter a number: 4**

**4 x 3 x 2 x 1 = 24**

__By Using def Function:__

```
def factorial(n):
if n == 0:
return(1)
else:
return(n*factorial(n-1))
a = int(input("Enter a number:"))
print("The Factorial of given number is",factorial(a))
```

**Output:**

**Enter a number: 4**

**The Factorial of given number is 24**

28 views0 comments