Jungle camping -- how do I count input from the string | SoloLearn: Learn to code for FREE!


Jungle camping -- how do I count input from the string

sounds = input() total = 0 gcount = sounds.count('Grr') rcount = sounds.count('Rawr') scount = sounds.count('Ssss') ccount = sounds.count('Chirp') total = gcount+rcount+scount+ccount for i in range(total): if (sounds == 'Grr'): total = total + 1 print('Lion'+" "*total) elif (sounds == 'Rawr'): print('Tiger'+" ") elif (sounds =='Ssss'): print('Snake'+" ") elif(sounds =='Chirp'): print('Bird'+" ") # the issue here is that I'd typically request number #of sounds by soundnum= int(input()), and #multiplying that by sounds. Code coach has made #it clear it wants only sounds as input then the #according output. Any suggestions?

3/30/2020 10:15:21 PM

👑 Shewe Uchi K 👑

3 Answers

New Answer



👑 Shewe Uchi K 👑 If there is a string such as words = "Hello how are you" How to count how many words are there? You can use words.split(" ") to tell python that " " or spaces between words makes them separate so now there are 4 words, separated into a list. sound = input().split(" ") a = [] for i in sound: if i == "Rawr": a.append("Tiger") elif i == "Chirp": a.append("Bird") elif i == "Ssss": a.append("Snake") else: a.append("Lion") print(' '.join(a)) I created a new list, and appended/added an animal into it according to its sound.


👑 Shewe Uchi K 👑 :) np