-1

There's a list with numbers. The while queue should run as long till the user inputs a number from the list.

new_list = [1, 2, 3]

while not True:
    user_input = input()
    if user_input in new_list:
        break
    else:
        print("false")

The queue currently doesn't stop if I enter for example 2.

khelwood
  • 55,782
  • 14
  • 81
  • 108

2 Answers2

0

the condition checks for the presence of the string '2' in new_list. you should convert the string to the coresponding type, in your case, the code should be user_input = int(input())

Alon Parag
  • 137
  • 1
  • 10
0

Because of the condition While not True, this will be not executed, have a look at bool values and how loop constructs work. Also, when reading from the command line you use input. If you don't say before what the input() should expect, it defaults to string. That means if you enter a number this number is not an integer or float because input() interprets it as string.

Try this:

new_list = [1, 2, 3]

while True:
    user_input = int(input('Number: '))
    if user_input in new_list:
        break
    else:
       print('False')
Higs
  • 384
  • 2
  • 7