In this post, we will see how we can find factorial of a given number using python
Logic
Factorial of number 5 is =>
5*4*3*2*1 = 120
Implementation
In this below code block, we will get to know use of
- if else statement
- for loop
- print method
num = 5 factorial = 1 if num < 0: print("factorial of", num, "is not possible") elif num == 0: print("factorial of", num, "is 1") else: for i in range(1, num + 1): factorial = factorial * i print("factorial of", num, "is", factorial)