0

'ellohay, orldway.' を返すには、pyglatin トランスレータが必要です。「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)
4

1 に答える 1

0

1 つの方法は、次のようにコードを記述することです。

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 に答える