Why does the if statement run even if the input does not match the elements in the list?

Question:

I am trying to get the input from the user and then checking if the input is present in the two lists. For some reason even if the input is ‘x’ the output is ‘yes. I am not sure why this is happening. What am I doing wrong?

texas  = ['austin', 'houston', 'dallas']
Newyork = ['albany','stony', 'nyc']
city  = input('enter city name?n>>')
if city in Newyork or texas:
    print('yes')
else: 
    print('no')
Asked By: Speedster_knight

||

Answers:

Try this:

texas = ['austin', 'houston', 'dallas']
Newyork = ['albany','stony', 'nyc']
city = input('enter city name?n>>')
if city in Newyork or city in texas:
    print('yes')
else: 
    print('no')

Explanation: you have to check twice: if city in Newyork and if city in texas

Answered By: rockzxm
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.