Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
goto
#11
(Feb-02-2021, 06:58 PM)jmabrito Wrote: There's a problem. Even if this number does exist, it continues to a voice that announces that number. pyttsx3
Thank you instruct me that, if "exists" you should go to the FOR, looking for another number. Thank you
Really don't understand what you are saying. Where pyttsx3 come into play? Here you just add some random numbers to a file. Both my code snippets will continue the loop if the number exists. Now, your loop is meant to draw 15 numbers. I assume some of these numbers may repeat/present in the file. So, the code is not guaranteed to add 15 numbers if that is what you want.
Really, show your actual code that has a "problem". I understand you may not speak english well, but try to use google translate so that it becomes more clear what you need and what the actual problem is.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#12
It is recording well in the file. when a number comes out regardless of whether or not it exists in the file, it goes to a cycle where the number is reported in voice. It turns out that if it already exists, it should not be mentioned, but rather go to the FOR. if the number does not exist this yes must be reported. if you want to send the program.
import random
import pyttsx3

fname = "bjjj.txt"
with open(fname) as f:
    numbers = f.readline().strip().split()
# print the numbers in the file:
print(numbers)
for _ in range(15): # 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')
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
    f = open('C:/Users/José Brito/AppData/Local/Programs/Python/Python39/WORK/ler.txt', 'r', encoding="utf8")
    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:
      print(voice, voice.id) #traz os idiomas de voz instalados em sua maquina
    
    speaker.setProperty('voice', voices[1].id) #define a voz padrao, no meu caso o portugues era o[2] (iniciando do zero)
    rate = speaker.getProperty('rate')          #nao exiuste a voz portuguesa
    speaker.setProperty('rate', rate-(200)) #muda velocidade da leitura, quando menor mais lento
    print(texto) #escreve o texto na tela
    speaker.say(texto) #define o texto que será lido
    speaker.runAndWait() #le o texto
    f.close() #fecha o modo deleitura do arquivo txt
buran write Feb-03-2021, 08:24 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#13
I would really suggest you find a good tutorial and get familiar with the basics like indentation, loops, conditions and so on. Just concatenating two snippets from internet without basic understanding of the script flow will not work.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#14
Thank you. The program ends after this change. In fact, the teachings on the internet need further study, insistence and practice. At this age, knowledge is no longer so easily assimilated. As a young man I was an analyst, planner, tester and implementer. I was never a programmer. My degree was in Accounting, stocks, invoicing and essentially human resources. In the last 20 years I worked for Baan, as the application had no payroll, assets I as an analyst made these applications. I have no intention of delving into programming, simply spending time in this pandemic. If I can finish the program, thank you. you must change line 32 to 0, English. Thank you in advance.
Reply
#15
please can ypu finish de program??? i dont know pulling to for
Reply
#16
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)
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')
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
f = open('C:/Users/José Brito/AppData/Local/Programs/Python/Python39/WORK/ler.txt', 'r', encoding="utf8")
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:
print(voice, voice.id) #traz os idiomas de voz instalados em sua maquina

speaker.setProperty('voice', voices[1].id) #define a voz padrao, no meu caso o portugues era o[2] (iniciando do zero)
rate = speaker.getProperty('rate') #nao exiuste a voz portuguesa
speaker.setProperty('rate', rate-(200)) #muda velocidade da leitura, quando menor mais lento
print(texto) #escreve o texto na tela
speaker.say(texto) #define o texto que será lido
speaker.runAndWait() #le o texto
f.close() #fecha o modo deleitura do arquivo txt


NOTE NOTE

if the number has already come out, very well it doesn't write in the table. But it must not be announced by the voice
buran write Feb-09-2021, 06:39 PM:
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
Reply
#17
[python]
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)
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')
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
f = open('C:/Users/José Brito/AppData/Local/Programs/Python/Python39/WORK/ler.txt', 'r', encoding="utf8")
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:
print(voice, voice.id) #traz os idiomas de voz instalados em sua maquina

speaker.setProperty('voice', voices[1].id) #define a voz padrao, no meu caso o portugues era o[2] (iniciando do zero)
rate = speaker.getProperty('rate') #nao exiuste a voz portuguesa
speaker.setProperty('rate', rate-(200)) #muda velocidade da leitura, quando menor mais lento
print(texto) #escreve o texto na tela
speaker.say(texto) #define o texto que será lido
speaker.runAndWait() #le o texto
f.close() #fecha o modo deleitura do arquivo txt

NOTE NOTE oh
I understand. so it records with indentation.
thank you
Larz60+ write Feb-09-2021, 11:02 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#18
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)
    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')
    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
        f = open('C:/Users/José Brito/AppData/Local/Programs/Python/Python39/WORK/ler.txt', 'r', encoding="utf8")
        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:
          print(voice, voice.id) #traz os idiomas de voz instalados em sua maquina
     
        speaker.setProperty('voice', voices[1].id) #define a voz padrao, no meu caso o portugues era o[2] (iniciando do zero)
        rate = speaker.getProperty('rate')          #nao exiuste a voz portuguesa
        speaker.setProperty('rate', rate-(200)) #muda velocidade da leitura, quando menor mais lento
        print(texto) #escreve o texto na tela
        speaker.say(texto) #define o texto que será lido
        speaker.runAndWait() #le o texto
        f.close() #fecha o modo deleitura do arquivo txt
Reply
#19
Quote:At this age, knowledge is no longer so easily assimilated.

FYI

I don't know what age you are, but I'm close to 75, and still have sparks that motivate me on a daily basis.
In the 1970's, I wrote a complete General Ledger system, published in Kilobaud magazine.

I am slowing down a bit, but expect, barring any unforeseen circumstances to still be going 20 years from now.
Very possible as folks in my family often live to be over 100, my uncle Jimmy was 110 when he passed.

I love life, love programming and electronics, and learning. Always looking for something new.
Reply
#20
Mr. Larz60+

Congratulations on your Youth and the pleasure of programming. As I said before, I programmed a little in Basic 40 years ago to hammer out some errors. I was essentially a consultant, installer and analyst. As an analyst and consultant at BAAN, we made changes to Portugal, payrol, assets, etc. I am 72 years old and retired. due to the pandemic and not being asleep I thought of listening to python programming lessons because I found it interesting. In Basic there was a GOTO instruction, directed to a program line, which sometimes caused errors. then with the goto a label the situation was resolved well. In the matter in question, when a number exists it must go to the FOR without this number being announced.
Thanks
Reply


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