How to write a Python Program to find all divisors of an integer

Python Program to find all divisors of an integer

In this python program write a program to find all divisors of an integer using the loop function and also used a second while loop function.

Write a Python Program to find all divisors of an integer using for loop

 

num = int(input("Please enter any integer to find divisors = "))

print("The Divisors of the Number = ")

for i in range(1, num + 1):
    if num % i == 0:
        print(i)

Here is the output of this program

Please enter any integer to find divisors = 90
The Divisors of the Number = 
1
2
3
5
6
9
10
15
18
30
45
90

Write a Python Program to find all divisors of an integer using the While loop

In this program, we discuss all divisors of an integer using the while loop.
num = int(input("Please enter any integer to find divisors = "))


i = 1

while(i <= num):
    if num % i == 0:
        print(i)
    i = i + 1

Here is the output of all divisors of an integer.

Please enter any integer to find divisors = 200
1  
2  
4  
5  
8  
10 
20 
25 
40 
50 
100
200

2 thoughts on “How to write a Python Program to find all divisors of an integer”

Leave a Comment

Verified by MonsterInsights