+ 5
JUNGLE CAMPING
I solved the jungle camping puzzle, but I'm wondering if anyone can tell me if there's an easier/more streamlined way this could have been done. Thanks in advance. Link to challenge: https://www.sololearn.com/coach/45?ref=app My solution: https://code.sololearn.com/cR7qwfC4f4Qb/?ref=app
10 Answers
+ 9
I went for this
noise = {'Grr':'Lion', 'Rawr':'Tiger', 'Ssss':'Snake', 'Chirp':'Bird'}
entry = input()
p = entry.split()
for x in p:
if x in noise:
print ((noise[x]), end=" ")
+ 8
You could have used the replace() method.
print(what_animal.replace("Grr", "Lion).replace("Rawr", "Tiger)...)
Nothing wrong with what you did, though!
+ 7
I did it this way
noise = str(input())
noise_list = noise.split()
animal = {"Grr":"Lion", "Ssss":"Snake", "Rawr":"Tiger", "Chirp":"Bird"}
answer = " "
for x in noise_list:
answer += animal[x] + " "
print(answer)
+ 4
This is what I did, using replace()
string = input()
a = string.replace('Grr', 'Lion')
b = a.replace('Rawr', 'Tiger')
c = b.replace('Ssss', 'Snake')
d = c.replace('Chirp', 'Bird')
print(d)
+ 2
đđ»Pleased kindlyâ€ïžupvoteđđ»
I did it using function,any other suggestions are highly welcomeđâ«ïžâ«ïžâ«ïž
https://code.sololearn.com/cBuE0jHEnNDY/?ref=app
+ 1
Thanks Russ! I'm going to try that. I figured there's got to be another method I could use that would have shortened what I wrote.
+ 1
sound = list(input())
for x in sound:
if x == "G":
print("Lion" , end = ' ')
elif x == "R":
print("Tiger" , end = ' ')
elif x == "S":
print("Snake" , end = ' ')
elif x == "C":
print("Bird" , end = ' ')
+ 1
noises = input().split()
#The noises are given all in one sentence, so I put them separately in a list
animals = {
'Grr': 'Lion',
'Rawr': 'Tiger',
'Ssss': 'Snake',
'Chirp': 'Bird'
}
#A dictionary to compare the inputs' sounds
animals_selected = [ ]
#We'll use it later
for i in noises: #For each noise in noises
if i in animals.keys(): #If the noise is in animals' keys
animals_selected.append(animals[i]) #Add its value to animals_selected
print(*animals_selected)
#The * assures that every item will be printed at the same line, without [] or , or ' just like the puzzle requires.
0
Here you go! Done in Python. I'll try c++ and Java next.
import re
#Produced By Joe Hutchens
word = input()
word.strip("")
#This extra material. You can rewrite the program with these lines of code#
pattern = r"Grr+|Ssss+|Rawr+|Chirp+"
x1 = re.findall(pattern,word)
#This is where the conversion happens#
word = re.sub("Grr","Lion",word)
word = re.sub("Ssss","Snake",word)
word = re.sub("Rawr","Tiger",word)
word = re.sub("Chirp","Bird",word)
#This will print the completed list with correct wording#
print(word)
- 1
my code in python
sounds={'Grr' : 'Lion', 'Rawr' : 'Tiger', 'Ssss' : 'Snake', 'Chrip' : 'Bird'}
hear=input()
animals=[]
slist= list(hear.split(" "))
for s in slist:
animals.append(sounds.get(s))
output=' '.join([str(i) for i in animals])
print(output)