I created two strings: edibles
and vz
. I wish to create a loop where the user is required to 1) input a food 2) be told if I am allergic to it. If the user types a name from the edibles
string, they're told of an allergy. If the user types a name from the vz
string, there is no allergy. I also include an option for a food item that is not included in either string.
At present, my code treats the items individually. I need assistance to figure out how to match input to the string without needing to add an elif
line for every item.
edibles = ["ham", "jachnun", "tiger", "ostrich head","eggs","nuts", "spam"]
vz = ["gefilte fish", "liver", "chrain", "sushi", "cholent"]
edv = vz + edibles
while True:
sval = input('Enter a food: ')
if sval == "spam":
print("I'm allergic to: " + sval + " Get it away from me")
elif sval == "jachnun":
print("I'm allergic to: " + sval + " Get it away from me")
elif sval == "gefilte fish":
print("I am not allergic to " + sval)
elif sval == "done":
break
else:
print(sval + " is an unfamiliar item" )
print('Thank you for respecting my allergies')