Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
goto
#21
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.
Reply
#22
in line
else:
              print (f'{k} EXISTE')
I want the program to go to the line

for r in range(12):
thank you
Reply
#23
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
Reply
#24
(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 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

[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
Reply
#25
?

while True:
    k = str(random.randint(1, 16))
    if k in numbers:
        break
    numbers.append(k)
Reply
#26
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ê.
Reply
#27
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
Reply
#28
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 Smile
Reply
#29
(Feb-11-2021, 11:19 PM)BashBedlam Wrote: 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ê.

[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
Reply
#30
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.
When a number comes out and says it exists, you should not announce it, record it or go to "digite the nr .:"
You should only go to "digite the nr .:" when and only "não existe", save to the file and announce the number.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to make input goto a different line mxl671 2 2,507 Feb-04-2020, 07:12 PM
Last Post: Marbelous
  goto problem Skaperen 1 2,776 Jan-27-2018, 01:11 PM
Last Post: stranac
  Go up script/menu(a goto command) foxtreat 7 8,316 Apr-24-2017, 05:58 PM
Last Post: micseydel
  Is there a goto like there is in BASIC? Luke_Drillbrain 24 14,810 Apr-24-2017, 06:00 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020