Menu

Sign in to track your progress and unlock all features.

Theme style

Log in
01. Reverse a String with Slicing and ReversedE02. Check if a string is a palindromeE03. Count Vowels Using String MethodsE

Problem No 3

Count Vowels Using String Methods

Easy

10 minute session

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.

Code editor
Loading editor…

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.

09:18 AM

Free preview includes 1 Teach Theory response and 1 AI hint on each of the first 3 lessons in this module.