Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

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.

IntermediatePhase 6 - Category 2: Array & String CombinationsExample 3 of 10
count-vowels-in-array-of-strings.py
1# Take array of strings
2n = int(input("Enter number of strings: "))
3arr = []
4for i in range(n):
5 arr.append(input(f"String {i+1}: "))
6
7# Count vowels
8vowels = "aeiouAEIOU"
9total_vowels = 0
10for s in arr:
11 for char in s:
12 if char in vowels:
13 total_vowels += 1
14
15print(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. 1

    Collect strings and initialize total_vowels.

  2. 2

    Visit each string and each character within it.

  3. 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.