Python Forum

Full Version: How to get all divisors from a number
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi people ,

I have what I presume is a really easy question but I cant get my mind wrapped around it..
How do I get a program to give me all divisors of a positive whole integer in a sorted list?
I have used a while loop with  while *number* % 2 == 0:
but I am really confused as to what to put in the if statement...

thanks..
Doesnotcompute
Show us your code.
There are so many solutions already there, see google:
http://stackoverflow.com/questions/17176...f-a-number
Keep it nice and simple: divisors = lambda x: [i for i in range(2, x) if x%i==0]