Write a program that reads a sentence from the user and conv

Write a program that reads a sentence from the user and converts it to \"Pig-Latin.\" Print the sentence in normal English, then underneath print it in Pig-Latin. For this project, you may use this simplified rule of Pig-Latin: in each word, remove the first letter and place it at the end, followed by \"ay\" Example: English: I slept most of the night Piglatin: lay leptsay ostmay foay hetay ightnay

Solution

Please find the required program along with its output. Please see the comments against each line to understand the step.

def piglatin():
wordsInSentence = str(input(\"Enter the input sentence to convert to pig-Latin: \")).split()   #read the user input sentence which needs to be converted to pig-Latin, and split it into individual words
  
for word in wordsInSentence:   #to print the user input in normal english
   print (word,end = \" \")

print()   #for newline

for word in wordsInSentence:   #iterate through each word in the sentence
print(word[1:] + word[0] + \"ay\", end = \" \")   # word[1:] will truncate the words first character; word[0] will print the first character of the word; and then add ay to the end
print ()   #for newline

piglatin()

------------------------------------------

OUTPUT:

 Write a program that reads a sentence from the user and converts it to \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site