Count Words Starting with Vowel

Count words starting with vowel.

IntermediatePhase 5 - Category 3: Word OperationsExample 8 of 10
count-words-starting-with-vowel.py
1# Take string input
2s = input("Enter a string: ")
3
4# Count words starting with vowel
5words = s.split()
6vowels = "aeiouAEIOU"
7count = 0
8for word in words:
9 if len(word) > 0 and word[0] in vowels:
10 count += 1
11
12print(f"Words starting with vowel: {count}")

Output

Enter a string: Apple Orange Banana
Words starting with vowel: 2

What's going on

Check first character of each word.

Key Concepts:

Split into words
Check if first character is vowel
Count matches