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?
2 Answers
+ 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)
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