Python中的音节计数

Python中的音节计数,第1张

Python中的音节计数

问题是您给它提供了大写的字符串,但是只比较了小写的值。可以通过添加

word = word.lower()
函数的开头来解决此问题。

def syllable_count(word):    word = word.lower()    count = 0    vowels = "aeiouy"    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 count == 0:        count += 1    return countprint(syllable_count('HAIRY'))  # prints "2"


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5631814.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存