Editor

Count Vowels

Strings · Beginner · 45 XP · about 5 min

Write a function called count_vowels(s) that counts the number of vowels (a, e, i, o, u) in a string.

The function should be case-insensitive (both 'A' and 'a' count as vowels).

Example

count_vowels("hello")      # Returns 2
count_vowels("AEIOU")      # Returns 5
count_vowels("rhythm")     # Returns 0
count_vowels("Beautiful")  # Returns 5

Requirements

  • Count both uppercase and lowercase vowels
  • Return 0 for strings with no vowels
  • Handle empty strings
def count_vowels(s):
# Your code here
pass
# Test your function
print(count_vowels("hello"))
print(count_vowels("AEIOU"))

Ready?

Accept the challenge to start writing. A small timer counts the time this page is in view.

Output appears here.