我正在尝试在字典中查找一些食物,如果找不到食物,我想调用 else 语句,但是由于某些原因,当找不到食物时,最后一个键和它在字典中的值被打印出来。我需要你的帮助,拜托。
fridge = {"cheese" : "so delicious", "crackers": "you will love it once you try it", "chicken soup": "delicous stuff"}
food_sought = "pepper"
if food_sought:
for food_sought in fridge:
print("I was able to find a something in our list of food: %s : %s" % (food_sought, fridge[food_sought]))
break
else:
print("We couldn't find the food you were looking for")