+ 2

Jungle Camping

Hello, While looking at the prior questions related to Jungle camping, what I could understand is as below. How can I make the output list in one line? Please explain not only the answer for my development.😭🙏 Thank you in advance! noise = input().split(" ") for i in noise: if i == "Grr": print("Lions") elif i == "Rawr": print("Tigers") elif i == "Ssss": print("Snakes") elif i == "Chirp": print("birds")

1st Apr 2022, 12:29 AM
Earl
Earl - avatar
5 odpowiedzi
+ 1
Add the strings to a `list` rather than directly printing them out. You can then use string.join( ) method after the loop completed, to merge `list` items. The task Description specified Tiger, Bird and Snake; so be sure to match the animal name by that specification, and make sure the letter case matches also. Lion rather than Lions Tiger rather than Tigers Snake rather than Snakes Bird rather than birds
1st Apr 2022, 12:54 AM
Ipang
+ 3
The print function has an optional end argument. By default it uses the new line character. To override this and use a single space use: print("text", end = " ") Note that this way you end up with a space at the end of your output which may not be what you want.
1st Apr 2022, 12:54 AM
Simon Sauter
Simon Sauter - avatar
+ 3
noise = input() animals = [] if noise == "Grr": animals.append("Lions") elif noise == "Rawr": animals.append("Tigers") elif noise == "Ssss": animals.append("Snakes") elif noise == "Chirp": animals.append("Birds") for i in animals: print(i, end='') # Good luck!!!
1st Apr 2022, 3:07 AM
CodeStory
CodeStory - avatar
0
You are camping alone out in the jungle and you hear some animals in the dark nearby. Based on the noise they make, determine which animals they are. 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 Sample Output: Tiger Bird Snake
1st Apr 2022, 12:29 AM
Earl
Earl - avatar