此搜索功能有效,但如果我搜索名为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