Count Vowels
Checking your account…
Sign in to save your code and progress across devices. The lesson and problem statement remain public.
Loading the interactive Practice workspace.If it does not appear, the problem and learning material remain readable, but browser execution is unavailable.Reload Practice workspace
Problem
Implement count_vowels(text). Return how many characters are a, e, i, o, or u, ignoring case.
Starter code
def count_vowels(text):
passTest cases
mixed-case
{
"args": [
"OpenAI"
]
}Expected: 4
Wizard outline
- Step 1: Count lowercase vowel membership
Translate the vowel definition into a direct membership predicate. The counting expression should encode exactly five accepted letters before case normalization is added.
- Step 2: Normalize case per character
Count uppercase and lowercase vowels identically. Lowercasing each character preserves the scan while making membership case-insensitive.
Footguns and prerequisites
- Uppercase vowels must count too.
- strings
Reviewed references
Recommended approach and implementation
Lowercase each character and count membership in the five-vowel set.
Why it works: The scan adds one exactly for each case-normalized vowel and zero for every other character.
def count_vowels(text):
return sum(character.lower() in 'aeiou' for character in text)