Ask Question
5 May, 14:25

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.

+5
Answers (1)
  1. 5 May, 14:53
    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 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