I am a beginner, and I have a question that I need help with.I need to count the number of syllables in a word.Here is what I have:
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 print(count("checked"))
But i am not able to get right result in my program, when i call count('checked')
should return '1'
, but it returned '2'
. can anyone help me? Thank You!
没有评论:
发表评论