+ 3

What's wrong in my code?-Pig Latin

I'm working this problem, and I think I did everything right. But I get 3/5. # As a remainder, the Pig Lating problem is that: you are given a sentence, and you have to to change every word to: you place the first letter in the end of the word, and add "ay" at the end. And Here's the code: inp= input() pig_lang=[] word= inp.split() for i in range(len(word)): list_word= word[i].replace(word[i][0], "") k= str(list_word) + str(word[i][0]) +"ay" pig_lang.append(k) print(" ".join(pig_lang))

5th Jan 2020, 2:44 AM
AbdullaH
AbdullaH - avatar
14 Antworten
+ 11
5th Jan 2020, 4:24 AM
David Ashton
David Ashton - avatar
+ 8
Zetra_coder the code is set to Private. I usually make my codes Public but since this is the answer to a Code Coach question which is worth XP, it's probably better not to broadcast it 🙂
5th Jan 2020, 3:42 PM
David Ashton
David Ashton - avatar
+ 3
replace: list_word= word[i].replace(word[i][0], "") with: list_word= word[i][1:] this will take everything but the first letter, rather than replacing it with an empty character.
5th Jan 2020, 3:00 AM
꧁༺ Jenspi ༻꧂
꧁༺ Jenspi ༻꧂ - avatar
+ 2
꧁༺Jenny༻꧂ Yes I didn't think of that. And thats also solved the problem. Thank you ❤
5th Jan 2020, 3:06 AM
AbdullaH
AbdullaH - avatar
+ 2
When you invoke word[i][0] the second time, you have destroyed the first letter previously, so what you're getting is the initial second letter.
5th Jan 2020, 4:44 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
David Ashton Very simplified code!! I have a question: when I enter in your link, I can't comment. And also the code isn't in your profile. How do you do that?
5th Jan 2020, 1:04 PM
Zetra_coder
Zetra_coder - avatar
+ 1
David Ashton An excellent code! I will try to write in this way!
6th Jan 2020, 9:25 AM
大菠萝啤
大菠萝啤 - avatar
0
You can try: str=input().split( ) for i,x in enumerate(str): str[i]=x[1:]+x[0]+"ay" print(" ".join(str))
6th Jan 2020, 12:58 AM
Hoà Xuân Nông
Hoà Xuân Nông - avatar
6th Jan 2020, 5:32 PM
ヽ(^。^)ノ✨ヽ(^。^)ノ
ヽ(^。^)ノ✨ヽ(^。^)ノ - avatar
0
I think u can try thi8s method
6th Jan 2020, 6:01 PM
Qwadwo Asante
Qwadwo Asante - avatar
0
I'm late to the party but here's my 1 line solution. print(" ".join([w[1:len(w)] + w[0] + "ay" for w in input().split()]))
6th Jan 2020, 7:21 PM
Adham Salama
Adham Salama - avatar
0
What does this do? i[1:]
7th Jan 2020, 2:13 AM
Michele
Michele - avatar
0
هله
7th Jan 2020, 5:39 PM
Zahraa Maithem
0
pig_latin = " ".join([(i[1:]+i[0]+"ay") for i in input().split()]) print(pig_latin)
6th Sep 2022, 9:13 PM
yonis Alvarez
yonis Alvarez - avatar