Ask Question
16 August, 03:37

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.

+1
Answers (1)
  1. 16 August, 06:44
    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?
Find 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 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