Ask 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 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.

+3
Answers (1)
  1. 20 June, 14:58
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers