Python Program to find all divisors of an integer

Write a Python program to find all divisors of an integer or number using for loop. In this Python example, the for loop iterate from 1 to a given number and check whether each number is perfectly divisible by number. If True, print that number as the divisor.

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)
Python Program to find all divisors of an integer

Python Program to find all divisors of an integer using a 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
Please enter any integer to find divisors = 100

1
2
4
5
10
20
25
50
100

In this Python example, we created a findDivisors function that will find and return all the divisors of the given number.

def findDivisors(num):
    for i in range(1, num + 1):
        if num % i == 0:
            print(i)
# End of Function

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

findDivisors(num)
Please enter any integer to find divisors = 500

1
2
4
5
10
20
25
50
100
125
250
500