
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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.
Example
Below is a demonstration for the same −
my_num = int(input("Enter a number :")) my_factorial = 1 while(my_num>0): my_factorial = my_factorial*my_num my_num=my_num-1 print("The factorial of the number is : ") print(my_factorial)
Output
Enter a number :7 The factorial of the number is : 5040
Explanation
- 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.
- Related Articles
- C++ Program to Find Factorial of a Number using Recursion
- Java Program to Find Factorial of a Number Using Recursion
- Haskell Program to Find Factorial of a Number Using Recursion
- Java program to find the factorial of a given number using recursion
- Python Program to Find the Sum of Digits in a Number without Recursion
- Factorial program in Java without using recursion.
- How to Find Factorial of Number Using Recursion in Python?
- Write a Golang program to find the factorial of a given number (Using Recursion)
- C++ program to Calculate Factorial of a Number Using Recursion
- Python program to find factorial of a large number
- Python Program to Find the Fibonacci Series without Using Recursion
- Python Program to Find the Length of the Linked List without using Recursion
- 8085 program to find the factorial of a number
- 8086 program to find the factorial of a number
- Java Program to Find Factorial of a number

Advertisements