So, while I was screwing around with some Project Euler (which has really made programming interesting), I got a weird syntax error.
My code is:
import math
primes = [2,3]
mult = 1
test = -1
def isPrime(n):
counter = 2
maxTest = math.sqrt(n)+1
nowTest = 5
while nowTest < maxTest:
if n % nowtest == 0:
return 0
elif len(primes) > counter:
counter += 1
nowTest = primes[counter]
else:
nowTest += 2
return 1
while len(primes) < 10001:
if isPrime(6 * mult + test) == 1:
primes.append(6 * mult + test)
elif test == -1:
test = 1
elif test == 1:
mult += 1
test = -1
if len(primes) >= 10:
print(primes[0:10]
if len(primes) < 10:
print(primes)
print(primes[10000])
The error seems to be with the:
if len(primes) < 10:
Help appreciated.
P.S. This would be for Project Euler number 7
Aucun commentaire:
Enregistrer un commentaire