1
我遇到了代碼只生成第一個單詞的前兩個字母,然後在運行時將'AY'附加到結尾的問題。我似乎無法弄清楚如何糾正這個錯誤。python的輸出代碼pig latin問題
def main():
strin = input('Enter a sentence (English): ')
strlist = strin.split()
i = 0
pigsen = ''
while i < len(strlist):
word = strlist[i]
j = 1
fc = word[0].upper()
pigword =''
while j < len(word):
pigword += word[j].upper()
j += 1
pigword += fc + 'AY'
pigsen += pigword + ' '
i +=1
print('Pig Latin: ' +str(pigsen))
main()
瞭解如何使用Python源代碼調試器並逐步完成代碼。錯誤將更容易找到。 –