Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 16

Count Vowels with a Loop

Medium

13 minute session

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.

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.

07:06 PM

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.