Question: # Part ( a ) - Function to count vowels in a word def count _ vowels ( w ) : # Define the vowels

# Part (a)- Function to count vowels in a word
def count_vowels(w):
# Define the vowels
vowels = 'aeiou'
# Initialize vowel count to 0
vowel_count =0
# Loop through each character in the word
for char in w:
# If the character is a vowel, increment the count
if char.lower() in vowels:
vowel_count +=1
return vowel_count
# Part (b)- Function to estimate the number of syllables in a word
def count_syllables(w):
# Define the vowels
vowels = 'aeiou'
syllable_count =0
# Check if the first character is a vowel and increment syllable count if so
if len(w)>0 and w[0].lower() in vowels:
syllable_count +=1
# Loop through the string and check for non-vowel followed by a vowel
for i in range(1, len(w)):
if w[i].lower() in vowels and w[i-1].lower() not in vowels:
syllable_count +=1
return syllable_count
# Part (c)- Test cases
# Test cases for count_vowels function
print(count_vowels('')) # 0
print(count_vowels('Z')) # 0
print(count_vowels('sloth')) # 1
print(count_vowels('SlOTh')) # 1
print(count_vowels('slothy')) # 1
print(count_vowels('ABACUS')) # 3
# Test cases for count_syllables function
print(count_syllables('')) # 0
print(count_syllables('Z')) # 0
print(count_syllables('i')) # 1
print(count_syllables('OWL')) # 1
print(count_syllables('tomato')) # 3
print(count_syllables('write')) # 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!