1
In Python, when the user type a non-existent option, how do I ask him to type again one of the desired options?
Make a program where the user can type several values and register them in a list.
If the number already exists inside, it will not be added.
At the end will be displayed all unique values typed in an order crescent.
Below is the program I’m creating:
numeros=[]
while True:
numeros.append(int(input('Digite um número: ')))
condicao=str(input('Deseja continuar? SIM ou NÃO? ')).upper()
if condicao=='NÃO':
numeros.sort()
unicos=list(set(numeros))
#O comando list(set(lista)) faz com que os números repetidos digitados não se repitam.
print(f'Os números digitados (excluindo os duplicados) foram {unicos}')
break
elif condicao!='SIM':
# Como faço para fazer o usuário retornar a "condicao" SIM ou NÃO?
print('Essa opção não existe. Tente de novo.')
The code is not good, but it seems to do what you want or not? If not, then please explain better what you want.
– Maniero
I need that when the user falls under the condition "YES" or "NO", and mistakenly type something that is not either of these two options, I want it to return to condition until you type "YES" or "NO".
– Lucas
If-Elif-Else, pronto https://www.tutorialspoint.com/python/python_if_else.htm
– FourZeroFive
Yeah, and it looks like that’s what your code is doing, if you don’t say what’s wrong and what you want it to help.
– Maniero
When I put the program to run and the user type something other than "YES" or "NO" the program returns for the user to enter a number instead of returning again the conditions "YES" or "NO". What I wanted to know is a way to make the user, in case he type wrong, repeat the operation until typing right.
– Lucas