23rd Jul 2021, 5:43 PM
Mas'ud Saleh
Mas'ud Saleh - avatar
3 Antworten
+ 1
Mas-ud Al-hassan What if there is "Grr Rawr Grr" ? Your output would be: Lion Lion because in if else condition only one part will be execute. So Try this: str = input() list = str.split() for i in list: if i == 'Grr': print("Lion", end = " ") elif i == 'Rawr': print("Tiger", end = " ") elif i == 'Ssss': print("Snake", end = " ") elif i == 'Chirp': print("Bird", end = " ")
23rd Jul 2021, 6:09 PM
A͢J
A͢J - avatar
+ 3
You could also use a dictionary https://code.sololearn.com/cPy5Bu5JitGv
24th Jul 2021, 1:50 AM
David Ashton
David Ashton - avatar
0
It works now. But why using 'for loop'? I mean suppose the inputs are 'Grr Rawr Grr', what the first loop would do?
23rd Jul 2021, 6:41 PM
Mas'ud Saleh
Mas'ud Saleh - avatar