Maker
Most folk just call me; Orange Joe
- Messages
- 10,371
- Location
- Don't ask questions
A video came up in my recommended videos called "Learn Python in one video", so I did.
I've tried to write something to test if a number is prime and for the most part it works but for some values it's not doing what I'd expect, could anyone help point me in the direction please?
Grr, putting it in quotes removes the indents, here's a screenshot instead:
That's outputting this:
My thinking is for any number, n, it'll attempt to divide it by 2, if there's a remainder it'll try 3, then 4, etc until either it finds one with no remainder, in which case n can't be prime, or tries every number up to half of n, in which case the number must be prime.
For anything above 4 it works as I'd hoped it would but for 0 to 3 it just says "None", what's causing this?
I've tried to write something to test if a number is prime and for the most part it works but for some values it's not doing what I'd expect, could anyone help point me in the direction please?
Grr, putting it in quotes removes the indents, here's a screenshot instead:
That's outputting this:
My thinking is for any number, n, it'll attempt to divide it by 2, if there's a remainder it'll try 3, then 4, etc until either it finds one with no remainder, in which case n can't be prime, or tries every number up to half of n, in which case the number must be prime.
For anything above 4 it works as I'd hoped it would but for 0 to 3 it just says "None", what's causing this?