[Solved] If an input is part of a list [duplicate]


It is going to depend on the type of data in the list. input returns everything as str. So if the list data type is float then the if statement will evaluate as True. For int data use the following:

items = [variable1, variable2, variable3]
choice = input("Input variable here: ")
if int(choice) not in items:
    print("Item not found")
else:
    print("Item found")

for float is must be:

items = [variable1, variable2, variable3]
choice = input("Input variable here: ")
if float(choice) not in items:
    print("Item not found")
else:
    print("Item found")

This should now correctly evaluate the if statement.

solved If an input is part of a list [duplicate]