+ 6

[ 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

23rd Nov 2020, 11:23 PM
AlTairTech
AlTairTech - avatar
10 Respostas
+ 11
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".
23rd Nov 2020, 11:41 PM
Gordon
Gordon - avatar
+ 16
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))
24th Nov 2020, 4:33 AM
David Ashton
David Ashton - avatar
+ 5
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)
24th Nov 2020, 12:22 AM
Gordon
Gordon - avatar
+ 4
Gordon You are my super hero! đŸ‘đŸŸ
24th Nov 2020, 12:59 AM
AlTairTech
AlTairTech - avatar
+ 4
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++
24th Nov 2020, 4:59 AM
David Ashton
David Ashton - avatar
+ 3
David Ashton can you help me out to solve this problem with C++?
24th Nov 2020, 4:34 AM
Misbah Ahmed
Misbah Ahmed - avatar
+ 3
David Ashton Appreciate it! đŸ‘đŸŸ
24th Nov 2020, 9:05 AM
AlTairTech
AlTairTech - avatar
+ 3
Misbah Ahmed Sorry mate, I’m not a C++ either! try to look out for it in the community! good luck #happycoding
24th Nov 2020, 9:16 AM
AlTairTech
AlTairTech - avatar
+ 2
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")
23rd Nov 2020, 11:34 PM
AlTairTech
AlTairTech - avatar
+ 2
quick question Gordon what’s with the ‘result’ var?
24th Nov 2020, 12:18 AM
AlTairTech
AlTairTech - avatar