Need help with 1000th prime http://codepad.org/r1doQ9AS Don't know how to loop it. Also When I wan't to divide a number by all the numbers in a list, instead of having it stop at the first number that meets the condition.
you have lots of loops, i'm not sure what you mean by "don't know how to loop it" here is one way to divide a number by all the numbers in a list http://codepad.org/ZhbZc2c9 you can replace lines 1 and 5-8 with: odd = range(7, 10000, 2) http://docs.python.org/library/functions.html#range the documentation should also be on your computer line 25 has a problem - it doesn't 'do' anything looks like you are testing odd numbers by dividing by previous primes found. one thing you are not doing is testing all the numbers in the list odd
Hm I was having problems with it running. It seemed like it would do a couple of numbers then an error would appear. Also thanks for the link! :) What do you mean by the last part though? I'm a bit of a dummy when it comes to math so I had to research prime numbers haha. One place I found told me I could find them by taking an odd number and dividing it by previous prime numbers. Is that wrong? Thanks!
**that is, previous prime numbers that were smaller than the square root of the number you want to test.
"... previous prime numbers that were smaller than the square root of the number you want to test..." i am pretty sure that is a valid test. you have a list (odd) which contains odd numbers but you are only testing one element of that list (odd[0]) - but looking at it closer, i see you are deleting elements after testing them so essentially you are traversing the list - just not used to seeing it done that way. there is a problem with lines 24 - 32, line 25 doesn't do anything and lines 26 and 29 are probably not doing what you think. an effective debugging technique is to put print statements in to print variables, results of tests, results of calculations ... etc - it lets you see what is really happening while it is running.
Join our real-time social learning platform and learn together with your friends!