25 XP

6. Count the vowels

Beginner strings loops

Write a function count_vowels(text) that takes a string text and returns how many vowels it contains, as a whole number.

The vowels are a, e, i, o and u, in lower case or as capitals (A, E, I, O, U). Count each vowel every time it appears. Nothing else counts: not y, and not spaces, digits or punctuation. If text is empty, or has no vowels, return 0.

Example 1

Inputtext = "Hello World"
Output3
Explanatione, o and o are vowels.

Example 2

Inputtext = "Python"
Output1
ExplanationOnly o counts: y is not a vowel here.

Example 3

Inputtext = "APPLE pie"
Output4
ExplanationCapitals count too: A, E, i and e.

Constraints

  • text has 0 to 100 characters.
  • It holds English letters, digits, spaces and punctuation.

Submit also runs 4 more tests you can't see.

Practises Strings (lesson 4).

Code
def count_vowels(text):
    """Count the vowels in a string.

    text: str, any characters; may be empty
    Returns: int, how many characters are a, e, i, o or u,
        in lower case or as capitals
    """
    # Write your code here
    pass