230k views
2 votes
Write a function to_pig_latin that converts a word into pig latin, by: Removing the first character from the start of the string, Adding the first character to the end of the string, Adding "ay" to the end of the string. So, for example, this function converts "hello"to "ellohay". Call the function twice to demonstrate the behavior. There is a worked example for this kind of problem.

1 Answer

5 votes

Answer:

def to_pig_latin(word):

new_word = word[1:] + word[0] + "ay"

return new_word

print(to_pig_latin("hello"))

print(to_pig_latin("latin"))

Step-by-step explanation:

Create a function called to_pig_latin that takes one parameter, word

Inside the function, create a new_word variable and set it to the characters that are between the second character and the last character (both included) of the word (use slicing) + first character of the word + "ay". Then, return the new_word.

Call the to_pig_latin function twice, first pass the "hello" as parameter, and then pass the "latin" as parameter

User MMP
by
3.6k points