I tried looping while to check if a condition was met. If the user types 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 stop asking the user to choose a number when he enters a number contained in the list, he continued to ask the user to choose a number. I found that if the user chose a number from the list the program should stop. Does anyone know where I'm going wrong?
I also tried doing this 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: ')
Q: I'm using a Windows 7; Python 3.6.5 and PyCharm.