Why is my algorithm for finding the sum of all prime numbers below 2 million so slow?
I\'m a fairly beginner programmer and this is what I came up with for finding the solution:
sum = 2
def isPrime(n):
if n % 2 == 0: return False
for i in range(3, int(n**0.5)+1, 2):
if n % i == 0: return False
return True
if __name__ == "__main__":
n = 1
while n < 2000000:
n += 2
if isPrime(n):sum += n
print sum