In this article, you will learn how to calculate Factorial in Python using While Loop.
What is the factorial of numbers? The factorial of any positive integer number n, denoted by n!, can be found by multiplying all the whole numbers from 1 to n together (1 × 2 × 3 … × n). For example, 7! = 7 x 6 x 5 x 4 x 3 x 2 x 1 = 5040. Factorial often appears in areas such as combinatorics, algebra, and probability theory.
Let’s see the factorial code in python.
Code:
number = 7
factorial = 1
start = 1
while start<=number:
factorial*=start
start+=1
print("The factorial is: ",factorial)
Output:
The factorial is: 5040
Reference:
Check out the Python original documentation for the usage of the While loop.
Related Article:
You may also calculate the factorial of any number using FOR loop in python language.
Pingback: How to take Factorial in python using FOR loop - AiOcta