Hi all,
I've been looking for primes on my pi (model b) using python. Here is my current program:
f = open("primesList", "w") #Opens a new blank file to write primes to
f.write("2 \n")
def primeCheck(number, primeList):
->prime = True
->for num in primeList:
->->if number % num == 0:
->->->prime = False
->->->break #Exits the for loop if it is not prime
->->if prime == True:
->->->primeList.append(number)
->->->f.write("%s \n" % str(number)) #Writes to the primeList file
primeList = [2]
number = 1 #Starts at one and then adds 2 to avoid all evens
while len(primeList) < 1000: #Will find the first 1000 primes (can be changed)
->number += 2
->primeCheck(number, primeList)
f.close()
I would like to find the first million primes as a project but, as I am using the pi, it is rather slow. How can I make it faster?
Many thanks
I've been looking for primes on my pi (model b) using python. Here is my current program:
f = open("primesList", "w") #Opens a new blank file to write primes to
f.write("2 \n")
def primeCheck(number, primeList):
->prime = True
->for num in primeList:
->->if number % num == 0:
->->->prime = False
->->->break #Exits the for loop if it is not prime
->->if prime == True:
->->->primeList.append(number)
->->->f.write("%s \n" % str(number)) #Writes to the primeList file
primeList = [2]
number = 1 #Starts at one and then adds 2 to avoid all evens
while len(primeList) < 1000: #Will find the first 1000 primes (can be changed)
->number += 2
->primeCheck(number, primeList)
f.close()
I would like to find the first million primes as a project but, as I am using the pi, it is rather slow. How can I make it faster?
Many thanks
Last edited: