统计元音字母

统计元音字母_第1张图片

#解法一
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')

你可能感兴趣的:(统计元音字母)