Hello people, am back here to discuss on how to find the factorial of a given number.

Generally, a factorial on given number is given by calculating its product with all the numbers below it.

Factorial is represented as `!`

For Example : 4! = 4 * 3 * 2 * 1 = 24

#### Task :

To find factorial of a given number.

#### Approach :

- Read input number for which the factorial is to be found using
`input()`

or`raw_input()`

. - Check whether the input number is negative and show appropriate message
- If the number entered is 0, print factorial as 1
- When the entered number is positive integer and greater than 1, initialize a variable factorial as 1 then run a for loop from 1 to the number+1
- Calculate the factorial as factorial * i
- Print the result

#### Factorial – Code Visualization

#### Program :

1 2 3 4 5 6 7 8 9 10 |
num = int(input("Enter a number: ")) factorial = 1 if num < 0: print("Please enter a positive integer") elif num == 0: print("The factorial of 0 is 1") else: for i in range(1, num + 1): factorial *= i print("The factorial of", num, "is", factorial) |