+ 1
Why doesn't it work? Jungle camping problem
animal = list((input().split()) for n in animal: if n == 'Grr': print ("Lion ") elif n == 'Rawr' print ("Tiger ") elif n == 'Ssss' print ("Snake ") elif n == 'Chirp' print ("Bird ")
3 Antworten
+ 3
You didn't close the opening list parenthesis in first line
And there are missing semicolons after elif statements
Also the output would come as for Grr Grr:
Lion
Lion
instead of Lion Lion but that is allowed as well
+ 8
Regardless of all that was mentioned, the firts line of the code can be shortened:
animal = list((input().split()))
animal = input().split()
- There is no need to have brackets around input()
- There is no need to convert the input result to list, this is done from pythom by using split()
+ 1
This will work for You. You have some mistakes in your code
animal = input().split()
for n in animal:
if n == 'Grr':
print ("Lion ")
elif n == 'Rawr':
print ("Tiger ")
elif n == 'Ssss':
print ("Snake ")
elif n == 'Chirp':
print ("Bird ")