pythontip 元音字母的数量

编写一个Python程序来计算字符串中元音字母的数量。
定义函数vowel_count(),参数为string(表示字符串)。
在函数中统计字符串中的元音字母数,并返回计数。

  1. 这道题关键是将得到的字符串转为单字母,for 变量 in 字符串可以遍历变量
  2. 如何把元音字母放到存储,这里使用集合 定义:变量={}

def vowel_count(string):
yuanyin={'a','e','i','o','u'}
count=0
for char in string:
if char in yuanyin:
count+=1
return count

获取输入字符串

input_string = input()

调用函数

print(vowel_count(input_string))

posted @ 2025-11-07 19:48  硫酸钡barit  阅读(0)  评论(0)    收藏  举报