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 ответов
+ 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