Count vowels from raw input

后端 未结 6 1762
轮回少年
轮回少年 2021-01-14 09:09

I have a homework question which asks to read a string through raw input and count how many vowels are in the string. This is what I have so far but I have encountered a pro

6条回答
  •  爱一瞬间的悲伤
    2021-01-14 09:51

    You can simplify this code:

    def vowels():
        vowels = 'aeiou'
        count = 0
        string = raw_input ("Enter a string: ")
        for i in string:
            if i in vowels:
                count += 1
        print count
    

    Strings are iterable in Python.

提交回复
热议问题