Lesson guide
What this Python exercise practices
Count Vowels Using String Methods is a beginner practice lesson that focuses on strings, formatting, traversal. It is designed to be solved in about 10 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- String values
- Basic indexing
Difficulty and time
- Level
- Beginner
- Estimated time
- 10 minutes
Related public exercises
Summary
Count the number of vowel characters (a, e, i, o, u) in a string, case-insensitive.
Problem statement
Write a function count_vowels(s) that returns the number of vowels in s. For this problem, vowels are the five letters a, e, i, o, u in either case. Do not count accented vowels (e.g., 'é' is not counted).
Task
Practice iterating over strings and using membership testing to count specific characters, with attention to case normalization.
Examples
Mixed case example
Input
count_vowels('Hello World')
Output
3
Explanation
Vowels are e, o, o -> total 3.
Input format
A single string s passed to count_vowels(s).
Output format
Return an integer equal to the count of vowels in s.
Constraints
0 <= len(s) <= 10^5. Only ASCII vowels a/e/i/o/u (and uppercase variants) are counted.
Samples
Sample input 0
count_vowels('AEIOU xyz')
Sample output 0
5
Explanation 0
All five vowels are present once.
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 on each of the first 3 lessons in this module.