0
I need some help for the Code Coach Jungle Camping
I am a beginner in Python and I can't find the right syntax for this exercise Could someone refer me please?
4 Respostas
0
I solved this one by importing the input string (containing the different animal sounds) into a list with noises.split(). After that, I used if statements to match noises to animals.
0
Thank you for your help.
0
I tried this but it doesn't work.
animal = {"Grr" : "Lion", "Rawr" : "Tiger" , "Sss" : "Snake", "Chirp" : "Bird"}
noise = list(str(input().split()))
if "Grr" in noise:
print(animal["Grr"])
if "Rawr" in noise:
print(animal["Rawr"])
if "Sss" in noise:
print(animal["Sss"])
if "Chirp" in noise:
print(animal["Chirp"])
0
When things don’t work, try trouble shooting by printing the results from each step. For example, if you do print(noise) after creating the list, you will get
['[', "'", 'R', 'a', 'w', 'r', "'", ',', ' ', "'", 'C', 'h', 'i', 'r', 'p', "'", ',', ' ', "'", 'S', 's', 's', 's', "'", ']']
It looks like your list is splitting each character as it gets added to the input string. Maybe you need to collect the input first, then split the whole string?