+ 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))
14 Réponses
+ 11
Here's a short solution
https://code.sololearn.com/ckb0e4z0RAPC
+ 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 🙂
+ 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.
+ 2
꧁༺Jenny༻꧂ Yes I didn't think of that. And thats also solved the problem. Thank you ❤
+ 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.
+ 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?
+ 1
David Ashton An excellent code! I will try to write in this way!
0
You can try:
str=input().split( )
for i,x in enumerate(str):
str[i]=x[1:]+x[0]+"ay"
print(" ".join(str))
0
A short and simple solution:
https://code.sololearn.com/cQ9wZv1ypQwc/?ref=app
0
I think u can try thi8s method
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()]))
0
What does this do?
i[1:]
0
هله
0
pig_latin = " ".join([(i[1:]+i[0]+"ay") for i in input().split()])
print(pig_latin)