0

python jungle animal question!!

im derping, someone tell me why this wont work plz! I thought i wws following the proper syntax for multiple replacements but obviously not! Thanks! noises = str(input()) animals = noises.replace("Grr", 'Lion').noises.replace('Rawr', 'Tiger').noises.replace('Ssss', 'Snake').noises.replace('Chirp', 'Bird') print(animals)

28th Feb 2020, 7:41 PM
Brenner Pieszak
Brenner Pieszak - avatar
4 Antworten
+ 3
You're on the right track, no need to repeat noises every time as it is not a method. You just need noises.replace.replace...You get it Edit. As side note x = str(input()) is redundant as input() reads automaticaly a string
28th Feb 2020, 7:55 PM
Mihai Apostol
Mihai Apostol - avatar
+ 4
Yes only one str object is required which can be link to further replace() functions. You can do that individually too like this noises = input() noises=noises.replace("Ssss","Snake") noises=noises.replace("Rawr","Tiger") noises=noises.replace ("Chirp","Bird") noises=noises.replace ("Grr","Lion") print(noises)
28th Feb 2020, 7:56 PM
DishaAhuja
DishaAhuja - avatar
+ 1
thank you both!!!
28th Feb 2020, 8:12 PM
Brenner Pieszak
Brenner Pieszak - avatar
+ 1
Brenner Pieszak You're welcome.
28th Feb 2020, 8:16 PM
Mihai Apostol
Mihai Apostol - avatar