2021年4月2日星期五

How to count number of syllables in a word in python?

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!

https://stackoverflow.com/questions/66927853/how-to-count-number-of-syllables-in-a-word-in-python April 03, 2021 at 12:56PM

没有评论:

发表评论