0

I am writing a program that has two lists set up, and then the user is prompted for input. I want to tell the program to do one thing if the users answer is found in one list, and do another thing entirely if the variable is in the second list.

I was thinking I could use an if statement but I dont know how to word it,


I need a way to say this in python:

if variable1 is in list1:
      print "You don't occupy that area!"
if variable1 is in list2:
      print "okay, now we're going to...."
2
Contributors
1
Reply
2
Views
11 Years
Discussion Span
Last Post by Ene Uran
0

You were very close:

# search lists

mammal_list = ['cat', 'dog', 'ape', 'cow']
bird_list = ['chicken', 'crow', 'quail', 'finch']

animal = raw_input("Enter an animal: ")

if animal in mammal_list:
    print "This animal is a mammal"
elif animal in bird_list:
    print "This animal is a bird"
else:
    print "This animal is not on any list"
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.