Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass
Created November 22, 2020 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffersGlass/1c2343d8d56d55253ee6986c57bfc72a to your computer and use it in GitHub Desktop.
Save JeffersGlass/1c2343d8d56d55253ee6986c57bfc72a to your computer and use it in GitHub Desktop.
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):
f.write("\n"+str(val))
primesFound += 1
val += 1
makePrimes(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment