Ask Question
5 February, 08:56

Pig Latin is a nonsense language. To create a word in pig Latin, you remove the first letter and then add the first letter and "ay" at the end of the word. For example, "dog" becomes "ogday" and "cat" becomes "atcay." Write a program named PigLatin that allows the user to enter a word and displays the pig Latin version.

+2
Answers (1)
  1. 5 February, 10:10
    0
    class PigLatin:

    # The user is prompted for input

    # the input is stored in userInput

    userInput = str (input ("Enter your word: "))

    # The pigLatinWord is created by concatenation

    # using python slicing feature

    # userInput[1:] mean the userInput from index 1 to the end

    # userInput[0] refer to the first letter of userInput

    pigLatinWord = userInput[1:] + userInput[0] + "ay"

    # piglatinword is displayed.

    print (pigLatinWord)

    Explanation:

    The code is written in Python and well commented. A class pigLatin is created. The user is prompted for input which is converted to String and assigned to userInput. Then python slicing is use to create the pigLatinWord. The first slice userInput[1:] return the letters after the first index till the end. userInput[0] return the first letter. We then add "ay" at the end to complete the pigLatinWord.

    Finally, the pigLatinWord is displayed.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Pig Latin is a nonsense language. To create a word in pig Latin, you remove the first letter and then add the first letter and "ay" at the ...” in 📙 Engineering if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers