小编ink*_*lot的帖子

python中的Pig拉丁字符串转换

我正在尝试创建一个将文本转换为猪拉丁语的函数:简单的文本转换,修改每个单词,将第一个字符移动到末尾并将“ay”附加到末尾。但我得到的只是一个空列表。有小费吗?

def pig_latin(text):
  say = ""
  words = text.split()
  for word in words:
    endString = str(word[1]).upper()+str(word[2:])
    them = endString, str(word[0:1]).lower(), 'ay'
    word = ''.join(them)
    return word

print(pig_latin("hello how are you")) # Should be "ellohay owhay reaay ouyay"
print(pig_latin("programming in python is fun")) # Should be "rogrammingpay niay ythonpay siay unfay"
Run Code Online (Sandbox Code Playgroud)

python for-loop function

2
推荐指数
1
解决办法
4万
查看次数

标签 统计

for-loop ×1

function ×1

python ×1