To perform this task, you need to create an auxiliary variable to count the number of laps the program has performed in the loop while
, this way, you can verify when the amount of errors reaches 10.
But of course this is just not enough, as you will need to create a conditional to verify when the number reaches 10. You can then do the following:
numero = int(input('Digite um número:'))
msg1 = 'Errado'
msg2 = 'Tá osso em'
cont = 0
while numero != 0:
if cont == 10:
print(msg2)
else:
print(msg1)
cont += 1
numero = int(input('Digite um número:'))
print('Certo')
Now it becomes a question, do you need the message to appear only once or do you need it every 10 laps ? If it’s every 10 laps, change your parole to if cont % 10 == 0
. Example:
while numero != 0:
if cont % 10 == 0: # A cada 10 voltas ele imprime a segunda mensagem.
print(msg2)
else:
print(msg1)
If you need to get out of the loop while
after the second message, you can use the declaration break
to end the repeat.
while numero != 0:
if cont == 10:
print(msg2)
break
else:
print(msg1)
And then André, blz? If it was to interrupt msg1 only when it appeared at msg2, it would be with this break command somehow?
– Glebson Santos
I’m sorry but I don’t understand your question, could you rephrase it, please? The break command is to get out of a loop, for, while or foreach
– André