0

pig_latin: join or append? (solved - it was both!)

My code is just printing the last word in the string. I'm thinking maybe I should amend but not sure what can and should be amended. Any pointers would be great. Thanks. https://code.sololearn.com/cZ1oDgN4PFN1 x = input() x = x.split() x = list(x) for i in x: x = (i[1:] + i[0] + 'ay') print(''.join(x))

15th Jan 2020, 9:25 PM
Alex
Alex - avatar
4 Réponses
+ 1
It should look like this. You're referencing x over and over again, so it doesn't work. https://code.sololearn.com/cRiDjZRbYsEZ/?ref=app
15th Jan 2020, 9:30 PM
Jianmin Chen
Jianmin Chen - avatar
+ 1
Alex, sorry, my mistake. I have changed it.
15th Jan 2020, 11:01 PM
Jianmin Chen
Jianmin Chen - avatar
+ 1
Nice one. Cheers. Makes perfect sense with the added []. That's what I was missing all along. All the iterations without them is what led me to having all the x! https://code.sololearn.com/cZ1oDgN4PFN1
15th Jan 2020, 11:11 PM
Alex
Alex - avatar
0
Thanks. Your code just prints out the words as they are entered. I've got this far: https://code.sololearn.com/cZ1oDgN4PFN1 #Only the last word is printed? How come y does not join? x = input().split() for i in x: y = (i[1:] + i[0] + 'ay') print(''.join(y)) An aside how is .split() any different to creating a list?
15th Jan 2020, 10:56 PM
Alex
Alex - avatar