当我输入"Hello, world"时,我需要我的 pyglatin 翻译器返回 'ellohay, orldway.。 但是我不确定需要插入什么代码 t 让它做我想做的事。 这就是我到目前为止所拥有的;
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)
一种方法是像这样编写代码:
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() 检查输入是否仅包含字母数字字符(或仅包含字母)。