Coaching Task - Pig Latin | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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)

6th Mar 2020, 3:51 PM
Alistair McLaren
Alistair McLaren - avatar
1 Resposta
+ 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.
7th Mar 2020, 2:59 AM
John Wells
John Wells - avatar