Skip to content
Exercise · Strings · lesson 9 of 10

Exercise: vowels

Write a function count_vowels(text) that returns how many Latin vowels a, e, i, o and u the string text contains. Uppercase vowels count too.

  • count_vowels("Hello") → 2
  • count_vowels("AEIOU aeiou") → 10
  • count_vowels("rhythm") → 0

Constraints: text consists of Latin letters, digits, spaces and punctuation and may be an empty string; the letter y is not a vowel.

Do not add extra imports unless the task says so explicitly.

vowels.py — python
python · 3 lines
Ctrl+Enter run · Esc leave editor

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way