Write a Program in Python to find the Factorial of a number
Factorial : The factorial of a number is the product of all the integers below it till 1. for example factorial of 5 is 5 x 4 x 3 x 2 x 1 which is 120.
It is a mathematical operation. If we want to calculate the factorial of 6 so it can be represented like 6! which means the product of all integers that fall between 1 & 6 (including 1 and 6 also)
6! = 6 x 5 x 4 x 3 x 2 x 1 = 720
4! = 4 x 3 x 2 x 1 = 24
Python Program to find the Factorial of number using For loop
In above code, n1 is a variable used to store the integer whose factorial is to be calculated.
Factorial can be calculated only for positive integers. so to check this condition, we used first if(if n1 < 0) statement
Factorial of 0 is one. so to check this condition, we used elif (elif n1 == 0)
In else part we used for loop and range function to multiply all those numbers from n1 to 1.
Python Program to find the Factorial of number using While loop
MCQ of Computer Science Chapter Wise
Disclaimer : I tried to give you the correct coding of ” Factorial of a number in Python” , but if you feel that there is/are mistakes in the code or explanation of “Factorial of a number in Python “ given above, you can directly contact me at firstname.lastname@example.org.