How to Find All Divisors of an Integer in Python


Here let us see how to find out all divisible numbers in a given integer with Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

n = int(input("Please input an integer: "))
print("All divisors of this input integer are: ")
i = 1
while i <= n:
    if n % i == 0:
        print(i)
    i += 1

Output:

Please input an integer: 18
All divisors of this input integer are: 
1
2
3
6
9
18

Please input an integer: 26
All divisors of this input integer are: 
1
2
13
26
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments