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 Réponse
+ 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.