Lesson guide
What this Python exercise practices
Count Vowels with a Loop is a intermediate practice lesson that focuses on strings, formatting, traversal. It is designed to be solved in about 13 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- String values
- Basic indexing
Difficulty and time
- Level
- Intermediate
- Estimated time
- 13 minutes
Summary
Count how many vowels appear in a given string (case-insensitive).
Problem statement
Given an input string, return the number of vowel characters it contains. Vowels are the letters a, e, i, o, u. The function should be case-insensitive — both uppercase and lowercase vowels count. Non-letter characters do not affect the count. This task practices iterating over characters, conditional checks, and simple accumulation.
Task
Write a function that iterates through a string and returns the number of vowels (a, e, i, o, u).
Examples
Basic example
Input
"Hello World"
Output
3
Explanation
The string "Hello World" contains the vowels e, o, o -> total 3.
Input format
A single string argument s passed to the function count_vowels(s).
Output format
An integer representing the count of vowels in the string.
Constraints
The input string length will be between 0 and 10,000 characters. Only English letters are considered; treat other characters as non-vowels. Time complexity should be O(n) where n is the string length.
Samples
Sample input 0
"AEIOUaeiou"
Sample output 0
10
Explanation 0
All characters are vowels; count is 10.
AI assistant
Ask me anything!
Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.
Chat history is temporary and will not be saved.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.