I need some help for the Code Coach Jungle Camping | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
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?

6th Feb 2020, 3:28 PM
Christophe
Christophe - avatar
4 ответов
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.
6th Feb 2020, 4:35 PM
Isabel
Isabel - avatar
0
Thank you for your help.
6th Feb 2020, 7:51 PM
Christophe
Christophe - avatar
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"])
6th Feb 2020, 9:36 PM
Christophe
Christophe - avatar
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?
6th Feb 2020, 9:56 PM
Isabel
Isabel - avatar