我需要我的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)
答案 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()检查输入是否仅包含字母数字字符(或仅包含字母)。