Jungle Camping Issue | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Jungle Camping Issue

I have you versions of code that I have written to try and solve this problem, and whilst both run perfectly fine when I test them in CodeBits, when I run it in the test it fails. noises = input().split() animals = '' for noises in noises: if noises == 'Grr': animals += 'Lion' + ' ' if noises == 'Rawr': animals += 'Tiger' + ' ' if noises == 'Ssss': animals += 'Snake' + ' ' if noises == 'Chirp': animals += 'Bird' + ' ' print(animals) - For this one it says that variable 'noises' as not been defined, yet it still says this when I try " for n in noises" noises = input().split() animals = '' for n in range(len(noises)): if noises[n] == 'Grr': animals += 'Lion' + ' ' if noises[n] == 'Rawr': animals += 'Tiger' + ' ' if noises[n] == 'Ssss': animals += 'Snake' + ' ' if noises[n] == 'Chirp': animals += 'Bird' + ' ' print(animals) - For this second one, when the input is 'Grr' 'Grr' it outputs: Lion Lion Lion - Yet in my CodeBits test run it does not do this and runs the correct output of: Lion Lion I am confused.

16th Jul 2023, 9:39 AM
Owain Hayes
Owain Hayes - avatar
5 Answers
+ 7
Owain Hayes , your both codes are correct and it is working...
16th Jul 2023, 10:10 AM
Riya
Riya - avatar
+ 7
Anton Drud , If it is noises also it works... though to avoid confusions we use different variables...
16th Jul 2023, 10:28 AM
Riya
Riya - avatar
+ 2
In the first one you should remove the s, so it says " noises = input().split() animals = '' for noise in noises: if noise == 'Grr': animals += 'Lion' + ' ' if noise == 'Rawr': animals += 'Tiger' + ' ' if noise == 'Ssss': animals += 'Snake' + ' ' if noise == 'Chirp': animals += 'Bird' + ' ' print(animals) "
16th Jul 2023, 10:25 AM
Anton Drud
Anton Drud - avatar
+ 1
Thanks both, yeah for some reason I went back to it now and didnt change the code at all and now it passes. Broken app.
16th Jul 2023, 5:51 PM
Owain Hayes
Owain Hayes - avatar
+ 1
s = input().split() c = { "Grr":"Lion", "Rawr":"Tiger", "Ssss":"Snake", "Chirp":"Bird" } for i in s: print(c[i], end=" ")
11th Aug 2023, 6:51 AM
N/A