Count letters | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Count letters

Given a text input and a letter, the program should count the number of times de given letter appears inside the given text. def letter_count(text, letter): count (letter) text = input() letter = input() print(letter_count(text, letter)) Why does the count formula doesnā€™t work?

16th Mar 2021, 2:29 AM
Daniel Lopez
2 Respostas
+ 1
The count() method belongs to the str class. You will also need to return the value from the function or your print() statement will output None. def letter_count(text, letter): return text.count(letter)
16th Mar 2021, 2:40 AM
ChaoticDawg
ChaoticDawg - avatar
0
Your function code don't have return statement. U can use cycle: m=0 for i in range(0,len(text)): if text[i]==letter: m+=1 return m
16th Mar 2021, 5:22 AM
Š˜Š»ŃŒŃ ŠœŠøрŠ¾ŃˆŠ½ŠøŠŗ
Š˜Š»ŃŒŃ ŠœŠøрŠ¾ŃˆŠ½ŠøŠŗ - avatar