Skip to content

Instantly share code, notes, and snippets.

Created Nov 22, 2020
What would you like to do?
from os import path
def isPrime(n):
for d in range(2, n):
if (n/ d).is_integer(): return False
return True
#for i in range(100):
# if isPrime(i): print(i)
def makePrimes(numToMake):
primesFound = 0
if path.exists('primes.txt'):
with open('primes.txt', 'r') as f:
lines = f.readlines()
if len(lines) > 0:
lastLine = lines[-1]
val = int(lastLine)
else: val = 2
else: val = 2
while primesFound < numToMake:
with open('primes.txt', "a+") as f:
if isPrime(val):
primesFound += 1
val += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment