-2

I was trying to make a simple If statement with a list but it doesn't work when I input one of the foods in the list, is there something I'm missing or is there a different way to do it, I'm pretty new so I don't really know a lot. Thanks :)

def main():
  food = ["French Fries","Nutella","Smoothies","Macaroni","Fish Sticks"]
  ask = input("What is your favorite food?")
  num=["1.","2.","3.","4.","5."]
  if(ask == food):
    print("Cool! I also like "+ask+" alot!")
  print("These are my top 5 favorite Foods:")
  for n in range(0, len(food)):
    print(num[n]+food[n])  
        
main()

2 Answers2

0
  • ask == food you are comparing a string with an entire list

  • instead you need to check if ask exists inside the list

     if ask in food:
    
-1

Your line - if(ask == food): seems illogical. Check the list comparison syntax in python, its pretty basic. You can't compare list like this. Use in operator instead.