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 Respuesta
+ 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.