
Then you will save 9 as a prime and add it to sum, but 9 is not prime.

You will check 9 against 2, and find it doesn't divide evenly. After the test for each prime, you are adding the prime. So the first time through the loop it will be 2, the second time it will be 3, and the 5, and so on.īut you will have other problems. No, you should change for i in range(1, int(test**0.5)+1, int(primes)):to for prime in primes:You can loop directly through the items in a list this way. So you think I should change for i in range(1, int(test**0.5)+1, int(primes)):With for prime in primes(1, int(test**0.5)+1, prime):English is not my first language so feel free to speak your mind if I’m not clear enough, and I’ll try to explain better :) And in this way focus on dividing by the primes, 3, 5, 7, 11 ect. In this way we don’t need to divide by every odd number, 3, 5, 7, 9 ect. So I attempted to create a list were new primes are added as the code iterates and then only dividing the next number to be tested with primes from that list. So the idea is that its ineficiant to divide a nummer, lets say 541, by every odd nummer up to the square root of 541. If you want to loop through the primes to test each one against counter, you should just use for prime in primes. You can't step through a sequence by multiple distances at the same time.


int(primes) is being given as the step argument to the range function. I don't understand what you are trying to do there.
