At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
Break only works within while/for loops http://docs.python.org/release/2.5.2/ref/break.html So what you are actually doing is for every odd number, creating a list starting at 2, all the way to x (line8) (@Line 9) Then using the first number in that list, 2, dividing your odd number by it and checking to see if X is equal to 2 (Which it isn't because you are only picking odd numbers) Obviously this will store every odd number because you are ALWAYS checking them against the integer 2. Try rethinking your usage of range in this function. =)
do the opposite case if there is not a remainder and they are not equal then break since it is not prime. so we move on to the next quicker. if you look for a remainder like now you are basically appending every situation that fulfills the if condition, but you just want to append the prime.
I also picked 2 for my range but one could just start at 3, won't matter, but you see I took the opposite case... # prime.py # finds primes up to 1000 list= for k in range(1001): if ((k%2)==1): for j in range(2,k+1): if( ((k%j)==0) and j
I was able to get my code to work after I broke yours apart a little Beeb. count = 0 x = 1 prime =  while count < 1000: x += 1 for i in range(2, x+1): if x%i == 0 and x != i: break elif not(x%i) and i == x: prime.append(x) count += 1 print prime I just have a question. I dont understand what is happening in this line elif not(x%i) and i == x: Can you please explain. Thanks