Python Program to find the factorial of a number without recursion
When it is required to find the factorial of a number without using recursion, the ‘while’ loop can be used.
Below is a demonstration for the same −
my_num = int(input("Enter a number :"))
my_factorial = 1
my_factorial = my_factorial*my_num
print("The factorial of the number is : ")
Enter a number :7
The factorial of the number is :
- The input number is takne from the user.
- A variable is assigned to 1.
- It is checked to see for being 0.
- If not, it is multiplied by the previous value in the variable.
- It is assigned to the same variable.
- This is done until the number reaches 0.
- It is then displayed as output on the console.
Published on 12-Mar-2021 12:32:54