The code does what is supposed to do for smaller values of n, but I would like to calculate the sum for all primes that are below two million, and that's where the code seems to take an endless amount of time. I am working with PyScripter. Is there any way to make this code more efficient?
def is_prime(a):
return all(a % i for i in range(2, a))
def sum_of_primes(n):
sum = 0
x = 2
while x < n:
if is_prime(x):
sum = sum + x
x = x+1
return sum
def main():
print(sum_of_primes(2000000))
if __name__ == '__main__':
main()