I coded a Python tool that calculates prime numbers within a given range. Then I decided that copying the numbers from the shell, creating a txt file, and pasting them every single time is a tad troublesome, and it would be very convenient if i can get the tool to insert the primes into a text file.
I tried this:
def calc():
while True:
x = int(input("Please specify the lower end of the range...."))
y = int(input("Please specify the upper end of the range...."))
for n in range (x,y):
if all(n%i!=0 for i in range (2,n)):
a=[]
a.append(n)
fo = open('primes.txt', 'w')
print (">>>Writing the values to primes.txt...")
print ("##########Calculated by my prime calculator##########", file = fo)
print ("", file = fo)
print ((a), file = fo)
fo.close
s = input('To do another calculation input yes, to quit input anything else...')
if s == 'yes':
continue
else:
break
calc()
EDIT:
Using with open("primes.txt", "a") as fo I solved the problem
However, I couldn't get Python to save n values to memory and append them to a growing list.
You guys are awesome. That part about Python being stupid was an attempt at a humorous start lol.