你如何制作一个不识别非字母字符的pyglatin翻译器?

时间:2015-03-14 00:59:54

标签: python non-alphanumeric

我需要我的pyglatin翻译才能返回ellohay,orldway。'当我输入' Hello,world。'但是我不确定需要插入什么代码才能让它做我想做的事情。这就是我到目前为止所拥有的;

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)

1 个答案:

答案 0 :(得分: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()检查输入是否仅包含字母数字字符(或仅包含字母)。