📌  相关文章
📜  问题 2 让我们创建一个将文本转换为猪拉丁语的函数:一个简单的文本转换,它修改每个单词,将第一个字符移到末尾,并将“ay”附加到末尾.例如,python 最终成为 ythonpay. - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:41.028000             🧑  作者: Mango

代码示例1
def pig_latin(text):
  say = []

  # Separate the text into words

  words = text.split()
  for word in words:

    # Create the pig latin word and add it to the list

    word = word[1:] + word[0] + "ay"
    say.append(word)

    # Turn the list back into a phrase

  return " ".join(say)

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"