Class 11 Exam  >  Class 11 Questions  >  Write a Python program to find factorial of a... Start Learning for Free
Write a Python program to find factorial of any number?
Most Upvoted Answer
Write a Python program to find factorial of any number?
Import math
n=int (input("enter the number:"))
result=math.factorial (n)
print(" factorial of",n,"is",result)
Community Answer
Write a Python program to find factorial of any number?
Python Program to Find Factorial of any Number


Factorial is the product of all positive integers from 1 to the given number. Factorial of a number n is denoted by n!, and it is defined as:

n! = n * (n-1) * (n-2) * ... * 2 * 1


Approach


The factorial of a number can be calculated using a for loop. We can iterate from 1 to the given number and calculate the product of all the numbers.


Algorithm


  1. Take input from the user and store it in a variable.

  2. Initialize a variable to store the factorial value as 1.

  3. Use a for loop to iterate from 1 to the given number.

  4. Multiply the factorial value with the current number in each iteration.

  5. Print the factorial value.



Code


```python
# Python program to find factorial of a number

# take input from the user
num = int(input("Enter a number: "))

# initialize the factorial value as 1
factorial = 1

# iterate from 1 to the given number
for i in range(1, num+1):
# multiply the factorial value with the current number
factorial *= i

# print the factorial value
print("Factorial of", num, "is", factorial)
```

Output


```
Enter a number: 5
Factorial of 5 is 120
```

Thus, the factorial of the given number is calculated using a for loop in Python.
Attention Class 11 Students!
To make sure you are not studying endlessly, EduRev has designed Class 11 study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Class 11.
Explore Courses for Class 11 exam

Top Courses for Class 11

Write a Python program to find factorial of any number?
Question Description
Write a Python program to find factorial of any number? for Class 11 2024 is part of Class 11 preparation. The Question and answers have been prepared according to the Class 11 exam syllabus. Information about Write a Python program to find factorial of any number? covers all topics & solutions for Class 11 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Write a Python program to find factorial of any number?.
Solutions for Write a Python program to find factorial of any number? in English & in Hindi are available as part of our courses for Class 11. Download more important topics, notes, lectures and mock test series for Class 11 Exam by signing up for free.
Here you can find the meaning of Write a Python program to find factorial of any number? defined & explained in the simplest way possible. Besides giving the explanation of Write a Python program to find factorial of any number?, a detailed solution for Write a Python program to find factorial of any number? has been provided alongside types of Write a Python program to find factorial of any number? theory, EduRev gives you an ample number of questions to practice Write a Python program to find factorial of any number? tests, examples and also practice Class 11 tests.
Explore Courses for Class 11 exam

Top Courses for Class 11

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev