131k views
5 votes
Write a program that converts a string into 'Pig Latin". To convert a word to pig latin, you remove the first letter of that word then append it to the end of the word. Then you add 'ay' to it. An example is down below:

English: I SLEPT MOST OF THE NIGHT
Pig Latin: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY
Write in Python.
8.12

1 Answer

6 votes

Answer:

def convert_to_pig_latin(text):

words = text.split()

pig_latin_words = []

for word in words:

pig_word = word[1:] + word[0] + 'ay'

pig_latin_words.append(pig_word)

return ' '.join(pig_latin_words)

text = 'I SLEPT MOST OF THE NIGHT'

print(convert_to_pig_latin(text)) # Outputs: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY

User Arvind Singh
by
7.4k points