到目前为止我的代码:
untranslated = open('english.txt','r')
vowels = ('a','e','i','o','u')
newWords = []
for lines in untranslated:
words = lines.split()
for word in words:
if word[0] in vowels:
word = word + 'yay'
else:
while word[0] not in vowels:
word = word[1:] + word[0]
word = word + 'ay'
print(word)
English.txt 文件的内容:
these are lines
meant to be translated
to piglatin
到目前为止,我已经翻译了所有单词,但我的问题是它没有返回到与输入相同的行。
我希望最终结果看起来像:
esethay areyay ineslay
eantmay otay ebay anslatedtray
otay iglatinpay
我该怎么做呢?
我得到的是:
esethay
areyay
ineslay
eantmay
otay
ebay
anslatedtray
otay
iglatinpay