Advertisement
davidhellam

Python: Linear Searches

Aug 19th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. pets = ["squirrel","cat","dog","mouse","bird","unicorn"]
  2. food = ["nuts","fish","bones","cheese","seeds","marshmallows"]
  3.  
  4. query = input("What animal do you want to feed? ").lower()
  5. found = False
  6. for count in range(len(pets)):
  7.     if query==pets[count] and not found:
  8.         print("Your "+query+" eats "+food[count]+"!")
  9.         found = True
  10. if not found:
  11.     print("Sorry, I have no information on feeding a "+query+"!")
  12.  
  13.  
  14.    
  15. query = input("What animal do you want to feed? ").lower()
  16. found = False
  17. count = 0
  18. while (not found and count < len(pets)-1):
  19.     if query==pets[count] and not found:
  20.         print("Your "+query+" eats "+food[count]+"!")
  21.         found = True
  22.     count=count+1
  23. if not found:
  24.     print("Sorry, I have no information on feeding a "+query+"!")    
  25.  
  26.  
  27. query = input("What animal do you want to feed? ").lower()
  28. if query in pets:
  29.     print("Your "+query+" eats "+food[pets.index(query)]+"!")
  30. else:
  31.     print("Sorry, I have no information on feeding a "+query+"!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement