Exercise 11

Write a Python algorithm that asks the user to input an integer and then displays all of its divisors.


n = int(input("Enter an integer: "))

print("The divisors of", n, "are:")
for i in range(1, n+1):
    if n % i == 0:

In this program:

  1. We first prompts the user to enter an integer n: and stores it in the variable n.
  2. Then we enters a for loop: that iterates from 1 to n (inclusive),
  3. Then we check if n: is divisible by each value of i in the loop.
  4. If it is: the program prints the value of i, which is a divisor of n.


Younes Derfoufi

One thought on “Solution Exercise 11: python algorithm that determines all divisors of given number”

Leave a Reply