Count vowels from raw input

后端 未结 6 1880
轮回少年
轮回少年 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:39

    Here's a more condensed version using sum with a generator:

    def vowels():
        string = raw_input("Enter a string: ")
        print sum(1 for x in string if x.lower() in 'aeiou')
    
    vowels()
    

提交回复
热议问题