In this article, you will learn how to take the factorial of a number using FOR loop in python language.
The factorial of any positive integer n>1 is the product of all positive integers less than or equal to n. For example, 5! = 5 * 4 * 3 * 2 * 1 which is equal to 120. Let’s do it in python programming language.
Code:
number = 5
factorial = 1
for i in range(1, number + 1):
factorial = factorial * i
print("The factorial is: ", factorial)
Output:
The factorial is: 120
Reference:
Check out the Python original documentation for a brief description.
Related Article:
You may also calculate the factorial of any number using the While loop in python language.
Pingback: How to calculate Factorial in Python using While Loop - AiOcta