0

我需要我的 pyglatin 翻译器返回“ellohay, orldway”。当我输入“你好,世界”时。但是,我不确定需要插入什么代码才能让它做我想做的事。这就是我到目前为止所拥有的;

pyg = 'ay'

input = raw_input("Please enter a sentence:")
print input

if len(input) > 0:
    input = input.lower()
    phrase = input.split( )
    pyg_words = []

    for item in phrase:
        if item.isalpha():
        first = item[0]
            item = item[1:] + first + pyg
             pyg_words.append(item)
    print ' '.join(pyg_words)
4

1 回答 1

0

一种方法是像这样编写代码:

pyg = 'ay'
input = raw_input("Please enter a sentence:")
print input

    if len(input) > 0 and input.isalpha:
    input = input.lower()
    phrase = input.split( )
    pyg_words = []

        for item in phrase:
            if item.isalpha():
                first = item[0]
                item = item[1:] + first + pyg
                pyg_words.append(item)
            print ' '.join(pyg_words)
            else:
                print 'Please enter a sentence that only contains letters.'

input.isalpha() 检查输入是否仅包含字母数字字符(或仅包含字母)。

于 2015-06-18T12:13:55.847 回答