Jianzhong H.

asked • 05/08/21

Use Python code to find the sum of all the primes below two million.

I tried but did not run. Please help!! Here is my code:



def findPrime(z):

for y in range(2, z):

if (z % y) != 0:

return False

break

else:

return True

break


primesL = []

for x in range(2, 2000000):

temp = x

findPrime(temp)

if findPrime(temp) == False:

primesL.append(int(x))


sumP = 0

q = int(max(primesL))

for n in range (0, q):

sumP = sumP + int(primesL[n])


print(str(sumP))


1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.