我正在用python制作猪拉丁翻译器。我想遵循拉丁猪的规则,该规则规定,不是第一个字母,而是第一个移动到结尾的声音。这样,“ tree”之类的词就变成了“ eeetray”,而不是“ reetay”。因此,我想让程序检测单词的开头是否有字母。到目前为止,这是我的代码:
import twoletterdigraphs
import threeletterdigraphs
pyg = 'ay'
original = input('Enter a word: ')
if len(original) > 0 and original.isalpha():
word = original.lower()
if word[0] + word[1] + word[2] in threeletterdigraphs.threeLetter:
first = word[0] + word[1] + word[2]
new_word = word + first + pyg
new_word = new_word[3:len(new_word)]
print(new_word)
elif word[0] + word[1] in twoletterdigraphs.twoLetter:
first = word[0]+word[1]
new_word = word + first + pyg
new_word = new_word[2:len(new_word)]
print(new_word)
else:
first = word[0]
new_word = word + first + pyg
new_word = new_word[1:len(new_word)]
print(new_word)
else:
print('empty')
twoletterdigraphs和threeletterdigraphs是python文件,只包含一个元组,其中元组列表映射到变量twoLetter或threeLetter。他们在这里:
twoLetter = ["sh" "tr" "ch" "bl" "br" "cl" "cr" "dr" "fl" "fr" "gl" "gr" "pl" "pr" "sc" "sk"
"sl" "sm" "sn" "sp" "st" "sw" "th" "tr" "tw" "wh" "wr"]
和
threeLetter = ["sch" "scr" "shr" "sph" "spl" "spr" "squ" "str" "thr"]
运行代码时,无论我使用哪个单词,它都只会将第一个字母移到末尾。如何解决?