Count Vowels in Array of Strings
Count English vowels across a Python list of strings. Students trace outer and inner traversals and keep a single total across every input string.
1# Take array of strings2n = int(input("Enter number of strings: "))3arr = []4for i in range(n):5 arr.append(input(f"String {i+1}: "))67# Count vowels8vowels = "aeiouAEIOU"9total_vowels = 010for s in arr:11 for char in s:12 if char in vowels:13 total_vowels += 11415print(f"Total vowels: {total_vowels}")
Output
Enter number of strings: 3 String 1: Hello String 2: World String 3: Programming Total vowels: 6
In this one
- Nest collection and text loops
- Keep a shared total
- Define the English vowel set
How it works
- 1
Collect strings and initialize total_vowels.
- 2
Visit each string and each character within it.
- 3
Increment the total on vowel membership.
Edge cases
What if the list is empty?
What if the list is empty?
The total remains zero.
Are repeated strings counted again?
Are repeated strings counted again?
Yes. Every stored occurrence is scanned.
What's going on
The outer loop chooses a string and the inner loop visits its characters. A listed vowel increases total_vowels.
Because the counter is outside both loops, it sums occurrences across the entire collection. Both English letter cases are listed; spaces and digits do not match. Repeated strings contribute repeated counts because this measures occurrences, not distinct text values.
What if the list is empty? The total remains zero.
Are repeated strings counted again? Yes. Every stored occurrence is scanned.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Where must the total be initialized?
Pick an answer to check it.
Question 2
What if the list is empty?
Pick an answer to check it.
Questions people ask
What if the list is empty?
The total remains zero.
Are repeated strings counted again?
Yes. Every stored occurrence is scanned.
Where must the total be initialized?
Before both loops.
๐Related Content
- ๐
Phase 6 - Learn Concepts
Review Phase 6 concepts and explanations
- ๐
Phase 6 - Quiz
Test your Phase 6 understanding with quiz questions
- ๐ป
Phase 6 - All Practice Problems
Explore all practice problems for Phase 6
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum