0
Do not call the variables name. When the program tries to open the file after closed, it does not open.
from time import strftime
n = 2
cl = 2
abrir_arquivo = open("C:/Users/lucas/Documents/Documento.rtf", 'w')
while(1):
m = 2**n - 1
v = 1
simples = int(m / 2 + 1)
o = 0
h = strftime('%D %H:%M:%S')
for c in range(0, simples):
if m % v == 0:
o = o + 1
v = v + 1
if o == 3:
break
if o < 3:
print('Esse número mercene é primo: %i. Ele é o M%i. Ele foi elevado à %i.'%(m,cl, n))
print(strftime('%D:%H:%M:%S'),' ', h)
**abrir_arquivo
abrir_arquivo.write('Esse número mercene é primo: %i. Ele é o M%i. Ele foi elevado à %i.'%(m,cl, n))
abrir_arquivo.close()**
cl = cl + 1
n = n + 1
I think your code was missing in the question, but why do you want to close and then open the same file?
– Woss
It is because I want that when I close the program it saves what has already been processed
– Lucas Batista
I will still make modifications to the code so that it takes the data that was saved in the file and continues processing from that point
– Lucas Batista