# How do you Find the Factors of a Number in a while Loop in Python?

In the program given below, we used the while loop to find the factors of a given number. This approach differs when compared to the for loop. Initially, we initialize the variable ‘a’ as 1 before starting the loop. We iterate the while loop till a <a+1. Now we check if the current value is a divisor of z or not. If yes, we print the number and increment the value of ‘a’. If not, we skip the number and continue with the next number.Â

                    
def factors(z):Â
a = 1Â

while(i < z+1):Â

if z % a == 0:Â

print(a)Â

a = a + 1Â

numb = int(input("Enter any numb : "))Â

print("The factors for {} are : ".format(numb))Â

factors(numb)

Output:

Enter any numb : 20Â

1Â

2Â

4Â

5Â

10Â

20



#### Related Topics

Share with friends

## Customize your course in 30 seconds

##### Which class are you in?
5th
6th
7th
8th
9th
10th
11th
12th
Get ready for all-new Live Classes!
Now learn Live with India's best teachers. Join courses with the best schedule and enjoy fun and interactive classes.
Ashhar Firdausi
IIT Roorkee
Biology
Dr. Nazma Shaik
VTU
Chemistry
Gaurav Tiwari
APJAKTU
Physics
Get Started