Count Words Starting with Vowel
Count words beginning with English vowels using Python. Students split whitespace and test the first character, including uppercase and punctuation cases.
1# Take string input2s = input("Enter a string: ")34# Count words starting with vowel5words = s.split()6vowels = "aeiouAEIOU"7count = 08for word in words:9 if len(word) > 0 and word[0] in vowels:10 count += 11112print(f"Words starting with vowel: {count}")
Output
Enter a string: Apple Orange Banana Words starting with vowel: 2
In this one
- Inspect a token's first character
- Handle both vowel cases
- Retain punctuation effects
How it works
- 1
Split into words.
- 2
Check each nonempty word's first character.
- 3
Increment when that character is a listed vowel.
Edge cases
Does Apple qualify?
Does Apple qualify?
Yes. Uppercase A is listed.
Does a token starting with a quote qualify?
Does a token starting with a quote qualify?
No. The first character itself must be a listed vowel.
What's going on
Each token is checked for a nonempty first character in a vowel string containing both cases. A qualifying token increments count.
Apple and orange count, but a token beginning with a quotation mark does not, even if its next character is a vowel. split already produces nonempty tokens; the explicit length guard makes the indexing assumption visible. Entire-word vowel counts are not needed.
Does Apple qualify? Yes. Uppercase A is listed.
Does a token starting with a quote qualify? No. The first character itself must be a listed vowel.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
What is inspected per token?
Pick an answer to check it.
Question 2
Does Apple qualify?
Pick an answer to check it.
Questions people ask
Does Apple qualify?
Yes. Uppercase A is listed.
Does a token starting with a quote qualify?
No. The first character itself must be a listed vowel.
What is inspected per token?
word[0].
๐Related Content
- ๐
Phase 5 - Learn Concepts
Review Phase 5 concepts and explanations
- ๐
Phase 5 - Quiz
Test your Phase 5 understanding with quiz questions
- ๐ป
Phase 5 - All Practice Problems
Explore all practice problems for Phase 5
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum