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:
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, fayluebayishfayStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started