+ 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!
7 ответов
+ 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.
+ 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.
+ 1
# why not to use built-in count method
def my_count(letter, word):
return word.count(letter)
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?
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()
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))
- 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))