. Write a function in python that accepts a sentence as the argument 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 NIGHTPIG LATIN: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY.
def Pig_latin(sentence):
# to extract words from string
word = sentence.split()
new_sentance=""
for i in range(len(word)):
temp=word[i]
#swap word
a=temp[0] #first character of word
b=temp[1:]+a #place fisrt chracter to last
word_fin=b+"AY "
new_sentance=new_sentance+word_fin;
print(new_sentance)
Pig_latin("I SLEPT MOST OF THE NIGHT")
Get Answers For Free
Most questions answered within 1 hours.