[ SOLVED ] The jungle camping challenge | Sololearn: Learn to code for FREE!


[ SOLVED ] The jungle camping challenge

I need help with this challenge :( It’s an easy one tho but I still can’t figure it out! • • • Task: You are given the noises made by different animals that you can hear in the dark, evaluate each noise to determine which animal it belongs to. Lions say 'Grr', Tigers say 'Rawr', Snakes say 'Ssss', and Birds say 'Chirp'. Input Format: A string that represent the noises that you hear with a space between them. Output Format: A string that includes each animal that you hear with a space after each one. (animals can repeat) Sample Input: Rawr Chirp Ssss

11/23/2020 11:23:32 PM


10 Answers

New Answer


1. Split the input from string to list by space anml_noise_list = anml_noise.split(" ") 2. Declare empty string result = "" 3. Loop over the list. for sound in anml_noise_list 4. Perform the logic (You got it right with if elif else here, well done!) 5. Not "Chirp Chirp", don't double. Same for result, no "Bird Bird" or "Lion Lion".


You can also use a dictionary animals = { "Grr": "Lion", "Rawr": "Tiger", "Ssss": "Snake", "Chirp": "Bird" } sounds = input().split() print(*(animals.get(sound) for sound in sounds))


Gordon You are my super hero! 👍🏾


Misbah Ahmed Sorry I'm not much of a C++ guy. I suggest you post a link to your attempt as a new question and use the tag C++ and you'll probably get help from the community. Even better, go to Discuss, select Most Popular, and search for jungle c++


Instead of printing directly, you should add the animal type to this string result += (" " + animal) in each iteration print result once at the end of program. (in case it is a function, return this result string)


This is my code down here: 👇🏾 # anml stands for animal anml_noise = input(" ") if anml_noise == "Rawr": print("Tiger") elif anml_noise == "Chirp Chirp": print("Bird Bird") elif anml_noise == "Ssss": print("Snake") else: print("Lion Lion")


David Ashton can you help me out to solve this problem with C++?


David Ashton Appreciate it! 👍🏾


Misbah Ahmed Sorry mate, I’m not a C++ either! try to look out for it in the community! good luck #happycoding


quick question Gordon what’s with the ‘result’ var?