I have wrote some code in Python to solve problem 10 of Project Euler: 'Find the sum of all the primes below two million'. My code works, but not optimal. It takes a lot of time to show the output.
When I am trying to do the problem with primes below 20000 it works. When I change it to 200 000 or 2 million, it doesn't show the output and it is just calculating and it takes a lot of time, whereas I expected it to be faster, since the calculations aren't too difficult. I've never had the output. It almost seems like it's an infinite loop. Does anyone know what the problem is?
This is my code:
answer = 0
for number in range (2, 2000000):
if number > 1:
for i in range (2, number):
if number % i == 0:
break
else:
answer += number
print(answer)