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

def syllable_count(word): \"\"\" Returns the number of syllables in the word. Fo

ID: 3591870 • Letter: D

Question

 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     syllables = ['a', 'e', 'i', 'o', 'u', 'y','ai']     last = re.findall(,'words')     print(last)     if count == 0:         count = 1     return count 

Explanation / Answer

def syllable_count(words):
   syllables = ['a','e','i','o','u','y','al']
   words = words.lower()
   count = 0
   for i in range(len(syllables)):
      
       for j in range(len(words)):
           if len(syllables[i]) == 1:
              if words[j] == syllables[i] :
                  if j > 1:
                     if words[j-1] in syllables:
                        continue
                  if syllables[i] == 'e':
                    if count == 0:
                       count = count + 1
                  else:
                    count = count + 1
                 
           if len(syllables[i]) == 2:
              if j< len(words)-1:
                 s = words[j] + words[j+1]
                 if s == syllables[i]:
                    count = count + 1;

   return count

print(syllable_count('Harry'))
print(syllable_count('HAIRY'))
print(syllable_count('hare'))
print(syllable_count('the'))