Write in python, syllable_count This function takes a word and returns the numbe
ID: 3589985 • Letter: W
Question
Write in python,
syllable_count
This function takes a word and returns the number of syllables in the word. For this exercise, assume that syllables are determined as follows: Each sequence of vowels a e i o u y, except for the last e in a word, is a vowel. However, if that algorithm yields a count of 0, change it to 1. For example,
the 1
def syllable_count(word):
"""
Returns the number of syllables in the word.
For this exercise, assume that syllables are determined as follows:
Each sequence of vowels a e i o u y, except for the last e in a word, is a vowel.
However, if that algorithm yields a count of 0, change it to 1.
:param word: the word whose syllables are being counted.
>>> syllable_count('Harry')
2
>>> syllable_count('HAIRY')
2
>>> syllable_count('hare')
1
>>> syllable_count('the')
1
"""
# replace pass below with your code
pass
the 1
def syllable_count(word):
"""
Returns the number of syllables in the word.
For this exercise, assume that syllables are determined as follows:
Each sequence of vowels a e i o u y, except for the last e in a word, is a vowel.
However, if that algorithm yields a count of 0, change it to 1.
:param word: the word whose syllables are being counted.
>>> syllable_count('Harry')
2
>>> syllable_count('HAIRY')
2
>>> syllable_count('hare')
1
>>> syllable_count('the')
1
"""
# replace pass below with your code
pass
Explanation / Answer
def syllable_count(word):
syllables=['a','e','i','o','u','y']
last=len(word)
print (last)
count=0
last_word=0
for i in word:
last_word+=1
if i in syllables and last_word!=last :
count+=1
elif i!='e' and i in syllables:
count+=1
if count==0:
count=1
return count;
print(syllable_count('the'))
OUTPUT: 1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.