0
Coaching Task - Pig Latin
HeLLO ALL, IāM WONDERInG IF YOU CAN ASSIST ME WITH THE PIG LATIN TASK. IāVE TrIED MaNY ATTEMPTS BUT CANāT SEEM To GET ThE FINAL OUTPUT. THE ClOsEST IāVE MANAGED To MAkE a lIST FROM The STRInG And ITERRATE THE WORD ARRANGEMENT FoR EACH ITem. HOWEVEr TrYINg to JoiN THis bAcK TOGETHEr IS WHERE IāM HAViNg the ISsuE. BELOW IS a COPY OF MY CODe SO FAR. import re def Convert(string): li = list(string.split(" ")) return li input = input() li = Convert(input) for l in li: output = re.sub(l[0], " ", l) + l[0] + "ay" print(output)
1 Answer
+ 3
You have two issues with your code. First: The sentence needs to be one line so "Hi there" becomes:
iHay heretay
Not:
iHay
heretay
change print to:
print(output, end=" ")
Second: Your substitution replaces all occurences with a space so "test" becomes:
es tay
change to l[1:] which returns the second though the last characters.