统计元音字母

在这里插入图片描述

#解法一
def getCount(inputStr):
    #numCount 用于计数
    numCount=0
    #i用于遍历
    for i in inputStr:
        if i in ['a','e','i','o','u']:
            numCount+=1

    return numCount

inputStr=input('请输入一串字符串>>')
print(getCount(inputStr))

#解法二
def getCount(inputStr):
    return len([c for c in inputStr if c in ['a','e,','i','o','u']])

getCount('aaaabbbbtyyiipp')

猜你喜欢

转载自blog.csdn.net/weixin_42610407/article/details/87888234