Write a python program that reads a word and prints the number of syllables in t
ID: 3670339 • Letter: W
Question
Write a python program that reads a word and prints the number of syllables in the word. For this program, assume the following rules are the only ones you need to determine the number of syllables (there are some special case words that do not follow these rules and we will NOT test for those): Each vowel (a,e,i,o,u,y) counts as 1 syllable except as noted below A sequence of adjacent vowels count as 1 syllable An ‘e’ at the end of a word does not count If the program determines there are no syllables, then set the count to 1 syllable
Here are some examples:
Please give me a word: harry
The word harry has 2 syllables.
Please give me a word: hairy
The word hairy has 2 syllables.
Please give me a word: hare
The word hare has 1 syllables.
Please give me a word:
the
The word the has 1 syllables.
Explanation / Answer
def syllables(word):
count = 0
vowels = 'aeiouy'
word = word.lower().strip(".:;?!")
if word[0] in vowels:
count +=1
for index in range(1,len(word)):
if word[index] in vowels and word[index-1] not in vowels:
count +=1
if word.endswith('e'):
count -= 1
if word.endswith('le'):
count+=1
if count == 0:
count +=1
return count
inputMsg=raw_input("Enter the String");
print "The word"
print inputMsg
print "has"
print syllables(inputMsg)
print "Syllable"
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.