Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in python that reads a word and prints the number of syllables i

ID: 3671512 • Letter: W

Question

Write a program in python 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

inputWord = str(input("Enter a word: "))
vowels = ('a','e','i','o','u','y','A','E','I','O','U','Y')
lastVowel = False
lastCons = False
currVowel = False
currCons = False
syllablesCount = 0
for i in range(len(inputWord)):
letter = inputWord[i]
if letter in vowels:
currVowel = True
currCons = False
else:
currVowel = False
currCons = True
if currCons == True and lastVowel == True:
syllablesCount += 1
lastVowel = currVowel
lastCons = currCons
lastStart = len(inputWord) - 1
lastEnd = len(inputWord)
last = inputWord[lastStart:lastEnd]
if last == "a" or last == "i" or last == "o" or last == "u" or last == "y" or last == "A" or last == "I" or last == "O" or last == "U" or last == "Y":
syllablesCount += 1
if syllablesCount == 0:
syllablesCount = 1
print("There are %d syllables" % syllablesCount)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote