-
-
Save JeffersGlass/1c2343d8d56d55253ee6986c57bfc72a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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