Find factors of a number in python; Through this tutorial, i am going to show you how to find factors of a given number in python using for loop, while loop and function.

Factor, in mathematics, **a number or algebraic expression that divides another number or expression evenly—i.e., with no remainder**. For example, 3 and 6 are factors of 12 because 12 ÷ 3 = 4 exactly and 12 ÷ 6 = 2 exactly. The other factors of 12 are 1, 2, 4, and 12.

## Python Program to Find the Factors of a Number

See the following python programs to python program to find factors of a number using for loop, while loop and function; as shown below:

- Python Program to Find the Factors of a Number using For Loop
- Python Program to Find the Factors of a Number using While Loop
- Python Program to Find the Factors of a Number using Functions

### Python Program to Find the Factors of a Number using For Loop

- Step 1 – Get input a number from user in program
- Step 2 – Iterate For Loop over every number from 1 to the given number
- Step 3 – If the loop iterator evenly divides the provided number i.e.
`number % i == 0`

print it. - Step 4 – Print factors of a number

num = int(input("Enter a number: ")) print("The factors of {} are,".format(num)) for i in range(1,num+1): if num % i == 0: print(i)

After executing the python program, the output will be:

Enter a number: 10 The factors of 10 are, 1 2 5 10

### Python Program to Find the Factors of a Number using While Loop

- Step 1 – Get input a number from user in program
- Step 2 – Iterate while Loop over every number from 1 to the given number
- Step 3 – If the loop iterator evenly divides the provided number i.e.
`number % i == 0`

print it. - Step 4 – Print factors of a number

# Python Program to find Factors of a Number number = int(input("Please Enter any Number: ")) value = 1 print("Factors of a Given Number {0} are:".format(number)) while (value <= number): if(number % value == 0): print("{0}".format(value)) value = value + 1

After executing the python program, the output will be:

Enter a number: 10 The factors of 10 are, 1 2 5 10

### Python Program to Find the Factors of a Number using Functions

- Step 1 – Create Function, which is calculate factors of number
- Step 2 – Get input a number from user in program
- Step 3 – Call Function with a number
- Step 4 – Print factors of a number

# Python Program to find the factors of a number # This function computes the factor of the argument passed def print_factors(x): print("The factors of",x,"are:") for i in range(1, x + 1): if x % i == 0: print(i) num = int(input("Enter a number: ")) print_factors(num)

After executing the python program, the output will be:

Enter a number: 10 The factors of 10 are, 1 2 5 10

## Recommended Python Tutorials

**Recommended:-**Python Program to Add Two Numbers

**Recommended:-**Python Program to Calculate Simple Interest

**Recommended:-**Python Program to Find Average of n Numbers

**Recommended:-**Python Program to ASCII Value of Character

**Recommended:-**Python Program to Calculate Compound Interest

**Recommended:-**Python Program to Check Leap Year

**Recommended:-**Python Program To Print Number Pattern

**Recommended:-**Python Program to Print Star Pattern

**Recommended:-**Python Program Calculate Sum of n Numbers

**Recommended:-**Python Program to Reverse Numbers

**Recommended:-**Python Program to Find Largest of n Numbers

**Recommended:-**Python Program to Find Power of Number

**Recommended:-**Python Program to Print Prime Number From 1 to N

**Recommended:-**Python Program to Find Square Root of Number

**Recommended:-**Python Program to Find Cube of Number

**Recommended:-**Python Palindrome Program

**Recommended:-**Python Program to Count Set Bits in a Number

**Recommended:-**Python Program for BMI Calculation

**Recommended:-**Python Program to Find Out Absolute Value

**Recommended:-**Python Random Number Generator Code

**Recommended:-**Python program for Zip, Zap and Zoom game

**Recommended:-**Python Program to Swap Two Numbers

**Recommended:-**Python Program to Find n-th term of Fibonacci Series

**Recommended:-**Python Program For Calculator