Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 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))