此搜索功能有效,但如果我搜索名爲Sarah的動物,並且列表中有兩個名爲Sarah的動物,它只打印其中的一個。我應該如何使它打印所有的搜索匹配?如何打印對象列表中的所有搜索匹配
def search():
choice = int(input("""
1 Name
2 Age
3 Specie
4 Gender
What do yo want to search for? """))
if choice == 1:
your_search = input("Write the animal name: ").capitalize()
for Animals in animal_list:
if your_search == Animals.name:
print(Animals)
break
else:
print("Sorry, couldn't find any animal called " + your_search + ", maybe check the spelling.")
我試圖除去休息時間,而那也打印else語句,即使它在列表中查找搜索的動物。 – Emiki