Count Vowels in Python
Character counting combines normalization, traversal, and membership tests.
What is Count Vowels?
Character counting combines normalization, traversal, and membership tests.
Count vowels in a line of text.
When should you use it?
- Learn Python syntax through a practical example.
- Build a foundation for larger programming problems.
- Test an idea quickly without a local setup.
Example code
main.py
text = "Code Utility"
# Count characters that belong to the vowel set.
count = sum(character.lower() in "aeiou" for character in text)
print(f"vowels={count}")
Expected output
vowels=5
How it works
Lowercasing makes one membership test work for both uppercase and lowercase input.
Change the values and run the program in the CodeUtility online Python compiler without installing Python locally.
Practice exercises
Modify the runnable example with the exercises below to build understanding beyond copying the result.
- Change the input and predict the output before running.
- Handle empty or invalid input.
- Wrap the logic in a function and add more test cases.