0
I tried to loop with while to check if a condition was met. If the user enters 0, 1 or 2 the program should stop asking the user which number he will choose. If the user chooses a number other than 0, 1 or 2, the program will ask the user which number he wants to choose.
lista = [0, 1, 2]
usuario =''
while usuario not in lista:
usuario = input('Escolha um número entre 0 e 2: ')
The behavior I observed was not what I expected. Instead of the program asking the user to choose a number when they enter a number contained in the list, he continued to ask the user to choose a number. I thought that if the user chose a number from the list the program should stop. Can anyone tell where I am missing?
I also tried to make that loop this way, but I had the same problem:
lista = [0, 1, 2]
usuario =''
while usuario != lista:
usuario = input('Escolha um número entre 0 e 2: ')
P.S.: I am using Windows 7; Python 3.6.5 and Pycharm.
That’s right, thank you.
– Alineat