+ 1

Please, help me with this task on Python

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)

24th Jun 2022, 10:51 AM
Api1623
Api1623 - avatar
4 Respuestas
+ 4
You are already completed python beginner course.. Revise the loops topic. Also learn about using the split method. Read about list in loop.. * take input. * split the input with the space into list. * iterate over list and print value from dictionary for the current key of loop. if you need, hope you can come back with your try again. Hope it helps..
24th Jun 2022, 11:08 AM
Jayakrishna 🇮🇳
+ 2
You have dictionary so Instead of if-else, better to use loop. For ex: if one input is "Grr" then print( Sounds["Grr"] ) will print "Lion". No need if-else.. Without dictionary: if input[I] == "Grr" : print( "Lion") Input have 4 strings with space separated so you need a loop .. and apply one of the above 2 ways... Hope it helps...
24th Jun 2022, 11:30 AM
Jayakrishna 🇮🇳
+ 1
So, that is my code: a = input() Sounds = { “Grr”:”Lion”, “Rawr”:”Tiger”, “Ssss”:”Snake”, “Chirp”:”Bird” } print(Sounds[a]) And i don’t understand how to loop the output.
24th Jun 2022, 10:57 AM
Api1623
Api1623 - avatar
+ 1
Jayakrishna🇮🇳 thank you! About the last step, does it mean that i need to use if, elif in my code ?
24th Jun 2022, 11:12 AM
Api1623
Api1623 - avatar