Question: In Python: 13. Pig Latin Write a program that accepts a sentence as input and converts each word to Pig Latin. In one version, to

In Python:

13. 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.

I am having a singular issue with my code, and that is the output is not correctly spacing out the words once theyre converted.

My code is as follows:

sentence = input("Please enter a sentence/phrase that you want converted into Pig Latin:")

words = sentence.split()

for i in range (len(words)):

pig_latin = words [i][1:] + words [i][0]

pig_latin += "ay"

words[i] = pig_latin

pig_latin_phrase = "".join(words)

print(pig_latin_phrase)

The output of a phrase looks like this:

In Python: 13. Pig Latin Write a program that accepts a sentence

What can i add to this code to help keep the spacing between the words?

Please enter a sentence/phrase that you want converted into Pig Latin: one fish, two fish, red fish, blue fish neoayish, faywotayish, fayedrayish, fayluebayishfay

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!