0

以 Codecademy pyglatin.py 翻译器为例,我试图扩展翻译器以一次包含多个单词。到目前为止,它读取第一个单词并翻译它,我想继续下一个单词,然后是下一个,直到没有更多单词存在。然后我想打印整个原始翻译输入。

定义猪拉丁():

pig = 'ay'

original = raw_input('Enter a phrase:').split(' ')

if len(original[0]) > 0 and original[0].isalpha():
    word = original[0].lower()
    first = word[0]
    if first == "a" or first == "e" or first == "i" or first == "o" or first =="u":
        new_word = word + pig
        print new_word
    else:
        new_word = word[1:] + word[0:1] + pig
        print new_word
        again = raw_input('Translate again? Y/N')
        print again

        if len(again) > 0 and again.isalpha():
            second_word = again.lower()
            if second_word == "y":
                return piglatin()
            else:
                print "Okay Dokey!"

else:
    print 'Letters only please!'
    return piglatin()

谢谢!

4

1 回答 1

0

你想要一个for循环。一个好的起点是:

for word in original:
于 2013-10-18T21:36:03.850 回答