我对编码是新手,这是我的第一次尝试。我想从语音语言中将单词分成音节
用语音语言中的单词组成音节的规则:
<>考虑所有辅音直到第一元音,考虑元音。 重复一遍例如:
ma-ri-a
a-le-ksa-nda-r
我已经走了这么远:
word = 'aleksandar'
vowels = ['a','e','i','o','u']
consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z']
for vowel in vowels:
if vowels in word:
index_1 = int(word.index(vowel)) - 1
index_2 = int(word.index(vowel)) + 1
print(word[index_1:index_2])
else:
print(consonants)
IDK出了什么问题,请帮忙! 提前感谢:)
这应该能解决你的问题
我已经改变了你的代码一点点,它的工作完美
输出为:
相关问题 更多 >
编程相关推荐