(Feb-11-2021, 09:47 PM)nilamo Wrote: You've got a for loop that only ever runs one time:for _ in range(1):
on line 9. You can just get rid of that (since it only ever runs once, the same thing will happen whether it's there or not). Then, once there's only a single loop, you can usecontinue
to skip the rest of the loop body. And I *think* that's what you're trying to accomplish.
Try this out, please:import random import pyttsx3 for r in range(15): fname = "bjjj.txt" with open(fname) as f: numbers = f.readline().strip().split() # print the numbers in the file: print(numbers) k = str(random.randint(1, 16)) if k not in numbers: print(f'{k} não EXISTE') numbers.append(k) else: print(f'{k} EXISTE') # skip the rest of the for loop continue with open(fname, 'w') as f: # open file in write mode f.write(f'{" ".join(numbers)}\n') # vai ler o ficheiro txt de nome ler # Instrucoes em https://youtu.be/BtwHAvsNaA8 # import pyttsx3 #pip instal pyttsx3 # le o texto que esta guardado em um arquivo .txt with open('C:/Users/José Brito/AppData/Local/Programs/Python/Python39/WORK/ler.txt', 'r', encoding="utf8") as f: texto = f.read() texto = 'Saiu o número ', k # não lê o ficheiro speaker = pyttsx3.init() # inicia serviço biblioteca voices = speaker.getProperty('voices') # metodo de voz # ver as vozes instaladas na maquina for voice in voices: # traz os idiomas de voz instalados em sua maquina print(voice, voice.id) # define a voz padrao, no meu caso o portugues era o[2] (iniciando do zero) speaker.setProperty('voice', voices[1].id) rate = speaker.getProperty('rate') # nao exiuste a voz portuguesa # muda velocidade da leitura, quando menor mais lento speaker.setProperty('rate', rate-(200)) print(texto) # escreve o texto na tela speaker.say(texto) # define o texto que será lido speaker.runAndWait() # le o texto
[quote]
Worked perfectly. I introduced these changes
print ®
a = input ("Enter the number:")
if a == '999':
sys.exit ()
else:
print ('ok')
and the numbers are no longer announced.
what he intended was that when the number already existed he would go to the instruction
k = str (........
already tried as with While, to no avail
Thanhs
[\quote]
Larz60+ write Feb-11-2021, 11:01 PM:
Please use proper bbcode see: https://python-forum.io/misc.php?action=help&hid=25
python tags for code
quote for quotes only
Please use proper bbcode see: https://python-forum.io/misc.php?action=help&hid=25
python tags for code
quote for quotes only