Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
goto
#31
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) 
#     for _ in range(1): # loop 15 times
        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')
             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:When "there is" "continue" the program goes to line 7 (a = input ...).
How do I NOT go to line 7 but go to line 18 (k = str (random .....)
You should go to line 7 only if the number is announced, to give the enter key
thanks Think
Reply
#32
Mr. Buran
Please complete and or modify the program to solve the problem. If necessary, it can be changed in its entirety. thanks
Reply
#33
Pleas try this code and let me know if it accomplishes what you want from it.
Os apelos experimentam este código e me avisem se ele conseguir o que você quer dele.

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 ()
Reply
#34
[quote="BashBedlam" pid='137630' dateline='1613610151']
Pleas try this code and let me know if it accomplishes what you want from it.
Os apelos experimentam este código e me avisem se ele conseguir o que você quer dele.

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 ()
[quote]
Thank you very very much, sir BashBedlan. Actually, I didn't know about shuffer at random.
It randomly collects the desired number of numbers, and there is no need to record it in a table, to find out if the number is already out.
It forced me to redo the mother program, because I am obligatorily recording in a table, recording the numbers and other elements. Com as suas orientações acabei o programa que propus fazer. Uma vez mais obrigado. jmabrito Dance Smile
[/quote]
Reply
#35
Program termination does not invalidate the previously formulated request. Based on the program I exposed, how to overcome the problem of a "GOTO" not allowed, but desired, because I want to go to line 18 and not to 7. thanks
Reply


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