Count Vowels in Array of Strings

Count total vowels in array of strings.

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

What's going on

Nested loops to count vowels in all strings.

Key Concepts:

Outer loop: strings
Inner loop: characters
Count vowels