+ 8

Help with the Letter Count Question (Python Beginner) Please!

Write a function that takes a string and a letter as its arguments and returns the count of the letter in the string. My code: def letter_count(text,letter): count=0 for i in text: if i == letter: count=count+1 return count text = input() letter = input() print(letter_count(text,letter)) The results keep on saying no output or it's 0. I don't know what I did wrong. Thanks!

7th Apr 2021, 8:21 PM
Lucy Su
7 Réponses
+ 1
Lucy, looks like a bug in Sololearn's Code Playground more than your code. This very simple program also outputs nothing right now when it should obviously print "3": print(3) You could email info@sololearn.com to report it as a bug or wait a few hours and see if it corrects itself. The people who read emails to info@sololearn.com take a few days to respond. I see nothing wrong with your code.
7th Apr 2021, 8:38 PM
Josh Greig
Josh Greig - avatar
+ 1
Now, I see it working most of the time with your code 25 minutes after my previous comment here. Sololearn has some pretty serious stability issues so you have to be patient with it sometimes. One other example of these issues is that every week, there are at least a few times that I can't answer a question. I hit "POST" and it just gets stuck on a loading animation.
7th Apr 2021, 9:07 PM
Josh Greig
Josh Greig - avatar
+ 1
# why not to use built-in count method def my_count(letter, word): return word.count(letter)
8th Apr 2021, 11:50 AM
iTech
iTech - avatar
0
def letter_count(): text = input() letter = input() if letter in text: the_count = text.count(letter) print(the_count) letter_count() Runs well, except with Test Case 2. Why now?
16th Sep 2021, 6:52 PM
Andrew Kim
Andrew Kim - avatar
0
def letter_count(): text = input() letter = input() if letter in text: the_count = text.count(letter) print(the_count) else: print (0) letter_count()
23rd Sep 2021, 10:19 AM
Matt Webb
0
Сделал проще: def letter_count(text, letter): x = text.count(letter) i = x return i print(x) text = input() letter = input() print(letter_count(text, letter))
8th Dec 2021, 6:02 PM
Roman Stribunov
Roman Stribunov - avatar
- 1
my try : def letter_count(text,letter): count=0 for i in text: if i == letter: count=count+1 return count text = str(input()) letter = input() print(letter_count(text,letter))
9th Oct 2021, 8:13 AM
Ambaliya Jignesh
Ambaliya Jignesh - avatar