Feb-02-2021, 03:26 PM
(Feb-02-2021, 01:11 PM)jmabrito Wrote:i run your program andimport random for r in range(15): for i in range(1): # se estivesse 5 mostrava 5 numeros #print(random.randint(1 ,25)) k=random.randint(1, 16) print (k) arq = "bjjj.txt" with open(arq ,'r+') as arquivo: numer = arquivo.readline() if not(str(k)) in numer: print ('não EXISTE') file1 = open('bjjj.txt', 'a+') file1.seek(0) file1.write(' ' + str(k)) file1.close() if (str(k)) in numer: print (' EXISTE') print(k) print(numer, end='')the variable k comes from a random compare with a txt that has inserted 2 4 9 12 8 3 and if is different from any of these numbers it writes, if it should not, go to random.The error is that it is always recording whether it already exists or not.
Traceback (most recent call last):
File "C:\Users\José Brito\AppData\Local\Programs\Python\Python39\teste3.py", line 4, in <module>
numbers = [int(line) for line in f]
File "C:\Users\José Brito\AppData\Local\Programs\Python\Python39\teste3.py", line 4, in <listcomp>
numbers = [int(line) for line in f]
ValueError: invalid literal for int() with base 10: '2 3 4 5 6 7 8 9 11 6'
>>>