I skipped a bunch of questions and landed on this one. I’ll revisit the others… have no worries!

Euler, again. Source: https://commons.wikimedia.org/wiki/File:Leonhard_Euler.jpg

Problem 10:

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.

How’d I solve it?

sumTotal = 0

#check if number is prime, return True / False
def is_prime(n):
  if n > 1:
    for i in range (2, n):
      if (n % i) == 0:
        return False
        return True
    return False

#loop to iterate through all numbers up to desired number
for x in range(2000000):
  if is_prime(x):
    sumTotal = sumTotal + x


This surprisingly took a long time to solve on my Ubuntu server… which leads me to believe there must be a more efficient method. I’ll do some research, and I’ll be sure and share anything that I turn up.