编写在句子中定义 aeiou 的字符串,其中包含每个变量的数量
作为 python 初学者,我需要帮助:
编写一个程序: 为每个元音定义一个计数器(例如 a_counter = 0 ) 提示用户输入提示:请输入您的句子: 捕获输入并将其存储在变量中 循环遍历用户输入并计算所有元音。 遍历字符串并计算所有元音后,显示以下消息:
用户输入中 a 或 A 的数量为 ## 用户输入
中 e 或 E 的数量为 ## 用户输入
中 i 或 I 的数量用户输入是 ##
用户输入中 o 或 O 的数量是 ##
用户输入中 u 或 U 的数量是 ##
y 或用户输入中的 Y 是 ##
如果我想包含输入中输出“用户输入”的句子该怎么办? –
I need help as a beginner in python:
Write a program that:
Defines a counter for each vowel (e.g a_counter = 0 )
Prompt the user for input with the prompt: Please enter your sentence:
Capture the input and store it in a variable
Loop through the user input and count all the vowels.
Once you have traversed the string and counted all the vowels, display the following messages:
The number of a's or A's in the user input is ##
The number of e's or E's in the user input is ##
The number of i's or I's in the user input is ##
The number of o's or O's in the user input is ##
The number of u's or U's in the user input is ##
The number of y's or Y's in the user input is ##
what if I want to include the sentence from the input where it outputs "user input" instead? –
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您需要计算字符串中的字母数量,我建议将字符串提供给
collections.Counter
。当打印输出时,您还可以通过循环遍历元音来节省大量的复制和粘贴操作:If you need to count letters in a string, I suggest feeding the string to
collections.Counter
. You can also save yourself a lot of copying and pasting by going over the vowels in a loop when it's time to print the output: