+ 1
Letter Count
Hey guys, I got a problem. ‘letter’ and ‘text’ are variables. And I want to count how many ‘letter’(e.g, a) in the ‘text’(e.g, apple). But the code I wrote doesn’t work. I hope you can help me find a solution. THX!!! This is the code: def letter_count(text, letter): x = str(text) y = str(letter) x.count(y) text = input() letter = input() print(letter_count(text, letter))
2 ответов
+ 4
The "return" is missing in your function
+ 5
Kai Z. ,
as Lisa already mentioned, you need to return the value (number of certain character in text)
what you not need is to convert text and letter to string, as they are already strings. so you can do the function like:
def letter_count(text, letter):
return text.count(letter)
text = input()
letter = input()
print(letter_count(text, letter))