Skip to content
Hello Python

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):
    pass
Test cases

mixed-case

{
  "args": [
    "OpenAI"
  ]
}

Expected: 4

Wizard outline
  1. 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.

  2. 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)
Similar exercises