Pig Latin
Write a program that accepts a sentence as input and converts each word to “Pig Latin.” In one version, to convert a word to Pig Latin you remove the first letter and place that letter at the end of the word. Then you append the string “ay” to the word. Here is an example:
English: I SLEPT MOST OF THE NIGHT
Pig Latin: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY
Pig Latin Program Code:
def pigLatinConversion(inputData):
# Split the input sentence into individual words
words = inputData.split()
# Initialize an empty list to store the converted words
convertedData = []
# Iterate through each word in the list of words
for word in words:
# Remove the first letter from the word and append it to the end
converted_word = word[1:] + word[0]
# Append "ay" to the converted word
converted_word += "ay"
# Add the converted word to the list of converted words
convertedData.append(converted_word)
# Join the converted words back into a sentence
converted_sentence = " ".join(convertedData)
# Return the final converted sentence
return converted_sentence
# Initialized the input data from the question
inputData = "I SLEPT MOST OF THE NIGHT"
#Call the method, pigLatinConversion
output_sentence = pigLatinConversion(inputData)
#Display Output
print(output_sentence)
Executed Output:
Iay LEPTSay OSTMay FOay HETay IGHTNay