Write a Python program to find the factorial of a number.

**Factorial of any non-negative number is the multiple of all the numbers smaller than or equal to n.**

**Example:** Factorial of 4 is 4*3*2*1=24.

There are several ways to find factorial of any number in Python, let’s see each of them.

## Iterative Method

1 2 3 4 5 6 7 8 9 10 | def factorial(n): f=1 #iterate from 2 to n (including) and multiply them for x in range(2,n+1): f = f*x return f num = int(input("Enter a number to find its factorial: ")) print(factorial(num)) |

**Output**

1 2 | Enter a number to find its factorial: 4 24 |

## Recursive Method

1 2 3 4 5 6 | #recursive function def factorial(n): return 1 if n==1 or n==0 else n*factorial(n-1) num = int(input("Enter a number to find its factorial: ")) print(factorial(num)) |

**Output**

1 2 | Enter a number to find its factorial: 5 120 |

## Using factorial() in Python

Python has inbuilt **factorial()** method defined in “**math**” module which return the factorial of non negative integral number.

**Syntax**

1 | math.factorial(n) |

### factorial() Parameters

**n**– Number whose factorial need to be calculated.

Let’s see an example.

1 2 3 4 | import math num = int(input("Enter a number to find its factorial: ")) print(math.factorial(num)) |

**Output**

1 2 | Enter a number to find its factorial: 6 720 |

If you have any doubts or suggestion then please comment below.