0

I have just started learning python,

I want the user input to be case sensitive (pets list) it only works if i only have one string in the pets variable, how do i make it work with a list of animals ?

user_input=input("What animal?")
pets =('dog') #i want to add A list of animals here
if(user_input.lower() == pets):
  print ('Please feed it!')
else:print(' No need to feed '+ user_input)
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Tomer
  • 9
  • 1

1 Answers1

1

Put the allowed strings in a list, then use in to check if the lowercase input is one of the items in that list.

user_input=input("What animal?")
pets = ['dog', 'cat', 'hamster']
if user_input.lower() in pets:
    print('Please feed it!')
else:
    print(' No need to feed '+ user_input)

Also you don't have to put brackets around if-statements in python.

ewz93
  • 2,444
  • 1
  • 4
  • 12