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')
>Solution :
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