Read a line of lowercase English text and print how many vowels (a, e, i, o, u) it contains.
What to build
A loop over the characters of a line.
Requirements
- Read the line.
- Count the characters that are
a,e,i,ooru.
Input
One line of lowercase letters and spaces.
Output
The number of vowels.
Constraints
The line has lowercase letters and spaces only.
Example
Input:
programming
Output:
3
Why it works
ch in "aeiou" is a single test that covers all five vowels, and it replaces a long chain of comparisons.
Examples
Example 1 · Input
programming
Expected output
3
Example 2 · Input
hello world
Expected output
3
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
ch in "aeiou" is True when ch is a vowel.
Solution
Show one correct solution (try it yourself first)
text = input()
count = 0
for ch in text:
if ch in "aeiou":
count += 1
print(count)