使用 for 循环计算用户输入中的单个字母
我正在努力完成一项任务,计算用户输入中的字母并返回在输入的句子中可以找到该字母的次数。
这就是我到目前为止所得到的:
sentence = input("write an sentence here: ")
count = 0
for character in sentence:
if e in character:
count += 1
print count
我收到错误。将不胜感激任何帮助。
I am struggling with a task, counting a letter from a user input and returning the number of times the letter can be found within the sentence from the input.
this is what I have so far:
sentence = input("write an sentence here: ")
count = 0
for character in sentence:
if e in character:
count += 1
print count
I am getting errors. Would appreciate any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只想计算字符串中的所有字母(不带空格),那么这里就可以了:
如果您想搜索某个字母:
If you just want to count all the letters in string, without spaces, then here you have it:
If you want to search for a certain letter: