Assume s is a string of lower case characters.
Write a program that counts up the number of vowels contained in the string s. Valid vowels are: 'a', 'e', 'i', 'o', and 'u'. For example, if s = 'azcbobobegghakl', your program should print:
Number of vowels: 5
For problems such as these, do not include raw_input statements or define the variable s in any way. Our automating testing will provide a value of s for you - so the code you submit in the following box should assume s is already defined.
> vowels = "aeiou"
> [x for x in "azcbobobegghakl" if x in vowels]
['e', 'e', 'i', 'a']
> len([x for x in "azcbobobegghakl" if x in vowels])
4
To count the number of vowels in a given string, s, you can use the following algorithm:
1. Initialize a variable, `num_vowels`, to 0. This variable will keep track of the count of vowels.
2. Iterate over each character, `char`, in the string `s`.
3. Check if `char` is a vowel. You can do this by using an if statement to check if `char` is equal to any of the valid vowels: 'a', 'e', 'i', 'o', or 'u'.
4. If `char` is a vowel, increment `num_vowels` by 1.
5. After iterating over all the characters in `s`, `num_vowels` will store the total count of vowels in the string.
6. Finally, print `num_vowels` to display the result.
Here's an implementation of the above algorithm in Python:
```python
num_vowels = 0
for char in s:
if char in ['a', 'e', 'i', 'o', 'u']:
num_vowels += 1
print("Number of vowels:", num_vowels)
```
This program will count the number of vowels in the string `s` and print the result.