Jungle Camping Python | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 2

Jungle Camping Python

Hello, I'm trying to figure out this task and I don't know why I have only 3/5 correct šŸ¤” maybe you can try to show me way where I did mistake, rather than to show me the answer šŸ˜‡ thank you šŸŒ¹https://code.sololearn.com/cNi0OkxmIwT3/?ref=app

11th Aug 2022, 6:04 PM
Sandra HeinzovĆ”
Sandra HeinzovĆ” - avatar
8 Respostas
+ 3
You are not using loop iteartion properly.. use the i value. Check for input : Grr Ssss Output should : Lion Snake But your code output wrong..
11th Aug 2022, 6:14 PM
Jayakrishna šŸ‡®šŸ‡³
+ 3
Hi, Sandra HeinzovĆ” ! 1) Instead of test if any of the animal sounds are in the list of input values, itā€™s better to test, one by one, if the input values are equal to any of the animals sounds. 2) Because there will never be two conditions that are true at the same time, it's better using 'if - elif - elif ā€¦ instead of four if statements. Example: res = [] for wd in my_input_list: if wd == "Coo": res.append(ā€œPigeonsā€) elif ā€¦ ā€¦
11th Aug 2022, 7:53 PM
Per Bratthammar
Per Bratthammar - avatar
+ 2
JayakrishnašŸ‡®šŸ‡³ thank you for directing me šŸ’Ŗafter 3hrs I finally solved it.. Pheww šŸ˜… My final code: For x in range(0, len(noise)) : if "Grr" in noise[ i ]: animal.append('Lion') i += 1 Elif... And so on Not quite elegant style I guess šŸ˜ Coding is beautiful, so much ways to solve one problemšŸ’Ŗ
11th Aug 2022, 8:44 PM
Sandra HeinzovĆ”
Sandra HeinzovĆ” - avatar
+ 1
Per Bratthammar thank you for answer. I wasn't sure when use if and when elif.. Thanks for explanation.
11th Aug 2022, 8:45 PM
Sandra HeinzovĆ”
Sandra HeinzovĆ” - avatar
+ 1
dier = { 'Grr': "Lion", 'Rawr': "Tiger", 'Ssss': "Snake", 'Chirp': "Bird" } geluiden = [] geluid = input().split() for dierGeluid in geluid: geluiden.append(dier[dierGeluid]) print(*geluiden)
26th Dec 2022, 10:01 AM
Laurent
0
I think, Simplest way is for i in noise : if i == "Grr" : animal.append("Lion ") .... You're welcome..
11th Aug 2022, 8:51 PM
Jayakrishna šŸ‡®šŸ‡³
0
How to create a unity game in sololearn
13th Aug 2022, 11:45 AM
Teach Computer
Teach Computer - avatar
0
How to create a calculator app using sololearn
13th Aug 2022, 11:46 AM
Teach Computer
Teach Computer - avatar