goto - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: goto (/thread-32289.html) |
RE: goto - Larz60+ - Feb-10-2021 I don't believe I have used a single goto for the past 35 to 40 years. In my book, and software that contains one, is software that was not well thought out before being written. RE: goto - jmabrito - Feb-10-2021 in line else: print (f'{k} EXISTE')I want the program to go to the line for r in range(12):thank you RE: goto - nilamo - Feb-11-2021 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 use continue 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 RE: goto - jmabrito - Feb-11-2021 (Feb-11-2021, 09:47 PM)nilamo Wrote: You've got a for loop that only ever runs one time: [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] RE: goto - nilamo - Feb-11-2021 ? while True: k = str(random.randint(1, 16)) if k in numbers: break numbers.append(k) RE: goto - BashBedlam - Feb-11-2021 If you only need the numbers from 1 to 15 in random order, try this: se você só precisa dos números de 1 a 15 em ordem aleatória tentar este from random import shuffle numbers = [k for k in range (1, 16)] shuffle (numbers) print (numbers)I couldn't get pyttsx3 to run on my system so I can not test that part for you. Eu não consegui que pyttsx3 corresse no meu sistema então eu não posso testar essa parte para você. RE: goto - jmabrito - Feb-12-2021 Mr. Nilamo Did not work. it is recording numbers that have not been announced or come out. As it initially changed me, only with "continue", the cursor forced me to type enter whether the number existed or not. He did not correctly announce the numbers. To get all the numbers out, you would have to give + 200 enter. If in the while loop everyone who didn't exist didn't make me enter, it would be a great advantage. For the completion of the program it will only be necessary this while RE: goto - BashBedlam - Feb-12-2021 After reading your email, I believe that this is what you are trying to accomplish. Let me know if this is correct. Depois de ler seu e-mail, acredito que é isso que você está tentando realizar.Deixe-me saber se isso está correto. import pyttsx3 from time import sleep from random import shuffle numbers = [k for k in range (1, 16)] shuffle (numbers) print ('\n\n\n\n') speaker = pyttsx3.init () voices = speaker.getProperty ('voices') speaker.setProperty ('voice', voices [1].id) speaker.setProperty ('rate', 100) for count in range (15) : input ('\nPressione digitar para o próximo número.') output = f'o número saiu {numbers [count]}' print (output) speaker.say (output) speaker.runAndWait () sleep (1) speaker.say (output) speaker.runAndWait ()Felicidades RE: goto - jmabrito - Feb-12-2021 (Feb-11-2021, 11:19 PM)BashBedlam Wrote: If you only need the numbers from 1 to 15 in random order, try this: [quote] Thanks for the work as well as for the Portuguese translation. I don't know if pyttsx3 doesn't work for you, because you should change it to 0 in the 'voice' line, voices [0] .id) #define the default voice. mr. Nilano change de program but Did not work. it is recording numbers that have not been announced or come out. As it initially changed me, only with "continue", the cursor forced me to type enter whether the number existed or not. He did not correctly announce the numbers. To get all the numbers out, you would have to give + 200 enter. If in the while loop everyone who didn't exist didn't make me enter, it would be a great advantage. For the completion of the program it will only be necessary this while RE: goto - jmabrito - Feb-12-2021 import random import pyttsx3 import sys for r in range(15): print (r) a = input("Digite o nr.:") if a == '999': sys.exit() else: print ('ok') fname = "bjjj.txt" with open(fname) as f: numbers = f.readline().strip().split() # print the numbers in the file: print(numbers) while True: k = str(random.randint(1, 16)) # while k not in numbers: if k in numbers: print(f'{k} EXISTE') break numbers.append(k) else: print(f'{k} não 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 = 'Number ', 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[0].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:Please create bjjj.txt. After running it once, check that file. You will see that it already has content. |