Python Program to find Factorial of a number #7

Share with others

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

factorial of a number using for loop
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.

OUTPUT:

Python Program to find the Factorial of number using While loop

factorial of a number using while loop
Factorial of a number using while loop

OUTPUT:



MCQ of Computer Science Chapter Wise

1. Functions in Python

2. Flow of Control (Loop and Conditional statement)

3. 140+ MCQ on Introduction to Python

4. 120 MCQ on String in Python

5. 100+ MCQ on List in Python

6. 50+ MCQ on Tuple in Python

7. 100+ MCQ on Flow of Control in Python

8. 60+ MCQ on Dictionary in Python


Important Links

100 Practice Questions on Python Fundamentals

120+ MySQL Practice Questions

90+ Practice Questions on List

50+ Output based Practice Questions

100 Practice Questions on String

70 Practice Questions on Loops

70 Practice Questions on if-else


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 csiplearninghub@gmail.com.


Share with others

Leave a Reply

error: Content is protected !!