-5
Complete the function
buscar(lista, animal)
below, which receives two values:
- A list of animal names.
- The name of an animal you want to find on the list.
The function must return
True
if the animal exists on the list, andFalse
otherwise.When finishing the function, run the program and test it with some animals from the list.
Suggestions:
- tatu (exists in the list)
- rabbit (not listed)
Below is the code:
def buscar(lista, animal): pass # comando inútil (você pode apagá-lo se quiser) # Complete o código faltante aqui! # Programa principal: NÃO MODIFIQUE O CÓDIGO ABAIXO def programa_principal(): lista_animais = ['avestruz', 'cachorro', 'cavalo', 'gato', 'papagaio', 'tatu', 'urso', 'zebra'] bicho = input('Informe um animal: ') while bicho != '': if buscar(lista_animais, bicho): print(bicho, 'existe na lista!') else: print(bicho, 'não existe na lista!') bicho = input('\nInforme um animal: ') programa_principal()
Welcome to Stack Overflow in English. It seems your question contains some problems. We won’t do your college work or homework, but if you’re having difficulty somewhere specific, share your code, tell us what you’ve tried and what the difficulty is, so you increase your chances of getting a good answer. Be sure to read the Manual on how NOT to ask questions to have a better experience here.
– Icaro Martins