The objective of this python exercise is to build a function that turns text into pig latin, a simple text transformation that modifies each word by moving the first character to the end and appending "ay" to the end.
For example, python
ends up as ythonpay
.
I actually built this script, but I am confused as to why it is not iterating over all text.split
elements? And why it is only modifying the last element?
def pig_latin(text):say = ""# Separate the text into wordswords = text.split()for word in words:# Create the pig latin word and add it to the listnew_word = word[1:] + word[0] + "ay"say = "".join(new_word)# Turn the list back into a phrasereturn sayprint(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"