0

I want to find all the divisors of a number and essentially iterate through n. So for example if I called the function divisors(6) it would calculate 6/1, 6/2, 6/3 6/4 6/5 and 6/6, which would then print (6,2), (6,3) (6,6) and (6,1) but also find divisors of everything up to and including n. So it would also find (5,1) (5,5), (4,2),(4,1),(4,4) etc.

This is what I have so far:

def divisors(n) :

    for i in range(2,n+1):
       return i
return n

How would I accomplish this?

John
  • 29
  • 5
  • Hi John! Check this out. [What is the best way to get all the divisors of a number?](https://stackoverflow.com/questions/171765/what-is-the-best-way-to-get-all-the-divisors-of-a-number) – Paolo Feb 22 '19 at 21:12
  • thank you, i also made an edit to my question if you dont mind taking a look – John Feb 22 '19 at 21:12
  • `[f'({k},{i})' for k in range(1,n+1) for i in range(1,k+1) if k % i == 0 ]` – yatu Feb 22 '19 at 21:28

0 Answers0