Ask Question
10 May, 08:18

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.

+2
Answers (1)
  1. 10 May, 09:50
    0
    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"))

    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
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “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 ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers