+ 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
10 odpowiedzi
+ 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".
+ 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))
+ 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)
+ 4
Gordon You are my super hero! 👍🏾
+ 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++
+ 3
David Ashton can you help me out to solve this problem with C++?
+ 3
David Ashton Appreciate it! 👍🏾
+ 3
Misbah Ahmed Sorry mate, I’m not a C++ either!
try to look out for it in the community! good luck
#happycoding
+ 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")
+ 2
quick question Gordon what’s with the ‘result’ var?