Exercise 68

Write a Python function that takes as argument an integer n and that return the list of all divisors of n.

Solution

def allDivisors(n):
listDiv =[]
for i in range(1,n+1):
if n%i == 0:
listDiv.append(i)
return listDiv

# testing a function
print("List of all divisor of 20 is : ", allDivisors(20))
#The output is : List of all divisor of 20 is : [1, 2, 4, 5, 10, 20]
Younes Derfoufi
my-courses.net

Leave a Reply