+ 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)
4 Answers
+ 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..
+ 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...
+ 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.
+ 1
Jayakrishnađźđł thank you! About the last step, does it mean that i need to use if, elif in my code ?