Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
goto
#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


Messages In This Thread
goto - by jmabrito - Feb-01-2021, 09:49 PM
RE: goto - by Larz60+ - Feb-02-2021, 02:27 AM
RE: goto - by jmabrito - Feb-02-2021, 12:58 PM
RE: goto - by jmabrito - Feb-02-2021, 01:11 PM
RE: goto - by jmabrito - Feb-02-2021, 03:26 PM
RE: goto - by buran - Feb-02-2021, 01:25 PM
RE: goto - by buran - Feb-02-2021, 01:43 PM
RE: goto - by jmabrito - Feb-02-2021, 03:32 PM
RE: goto - by buran - Feb-02-2021, 03:33 PM
RE: goto - by jmabrito - Feb-02-2021, 06:58 PM
RE: goto - by buran - Feb-02-2021, 07:27 PM
RE: goto - by jmabrito - Feb-02-2021, 10:19 PM
RE: goto - by buran - Feb-03-2021, 08:37 AM
RE: goto - by jmabrito - Feb-03-2021, 10:17 AM
RE: goto - by jmabrito - Feb-06-2021, 12:29 PM
RE: goto - by jmabrito - Feb-09-2021, 06:36 PM
RE: goto - by jmabrito - Feb-09-2021, 06:51 PM
RE: goto - by jmabrito - Feb-09-2021, 06:55 PM
RE: goto - by Larz60+ - Feb-09-2021, 11:10 PM
RE: goto - by jmabrito - Feb-10-2021, 04:12 PM
RE: goto - by Larz60+ - Feb-10-2021, 06:20 PM
RE: goto - by jmabrito - Feb-10-2021, 06:59 PM
RE: goto - by nilamo - Feb-11-2021, 09:47 PM
RE: goto - by jmabrito - Feb-11-2021, 10:49 PM
RE: goto - by nilamo - Feb-11-2021, 11:14 PM
RE: goto - by BashBedlam - Feb-11-2021, 11:19 PM
RE: goto - by jmabrito - Feb-12-2021, 12:24 AM
RE: goto - by jmabrito - Feb-12-2021, 12:10 AM
RE: goto - by BashBedlam - Feb-12-2021, 12:12 AM
RE: goto - by jmabrito - Feb-12-2021, 03:34 PM
RE: goto - by jmabrito - Feb-15-2021, 10:14 PM
RE: goto - by jmabrito - Feb-17-2021, 10:03 PM
RE: goto - by BashBedlam - Feb-18-2021, 01:02 AM
RE: goto - by jmabrito - Feb-18-2021, 09:43 PM
RE: goto - by jmabrito - Feb-18-2021, 09:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to make input goto a different line mxl671 2 2,510 Feb-04-2020, 07:12 PM
Last Post: Marbelous
  goto problem Skaperen 1 2,781 Jan-27-2018, 01:11 PM
Last Post: stranac
  Go up script/menu(a goto command) foxtreat 7 8,335 Apr-24-2017, 05:58 PM
Last Post: micseydel
  Is there a goto like there is in BASIC? Luke_Drillbrain 24 14,836 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