+ 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 Respostas
+ 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))