beginner
Count Vowels
Count the number of vowels in a string.
Practice string iteration and character checking.
📚 Concepts & Theory
String Iteration
for char in text:
if char in 'aeiou':
count += 1 🎯 Your Challenge
Write count_vowels that returns the vowel count.
📝 Starter Code
Python
def count_vowels(text):
pass
print(count_vowels('hello world'))
Solution
Python
def count_vowels(text):
vowels = 'aeiouAEIOU'
count = 0
for char in text:
if char in vowels:
count += 1
return count
print(count_vowels('hello world'))
Explanation
Check each character against vowels.
❓ Frequently Asked Questions
Iterate and check membership