< Back

Lab 6: Text Processing


Count Vowels

In a file called vowels.py, create a function called count_vowels(a_string). This function should print the number of vowels that are contained within the string.

Example

====== Loading Program ======
>>> count_vowels("Scotty")
1
>>> count_vowels("antidisestablishmentarianism")
11

Hint

You are going to be using the accumulator mechanism in this exercise. You will need some variable that will hold the current count of the number of vowels, and this variable's value should start at 0.

The structure for this is similar to that of Program 15 on page 51 of the textbook. However, you need to change what you do in the if statement.

Don't forget to print the count of vowels at the end of the function.