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], "") k= str(list_word) + str(word[i]) +"ay" pig_lang.append(k) print(" ".join(pig_lang))
Here's a short solution https://code.sololearn.com/ckb0e4z0RAPC
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 🙂
replace: list_word= word[i].replace(word[i], "") with: list_word= word[i][1:] this will take everything but the first letter, rather than replacing it with an empty character.
꧁༺Jenny༻꧂ Yes I didn't think of that. And thats also solved the problem. Thank you ❤
When you invoke word[i] the second time, you have destroyed the first letter previously, so what you're getting is the initial second letter.
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?
David Ashton An excellent code! I will try to write in this way!
You can try: str=input().split( ) for i,x in enumerate(str): str[i]=x[1:]+x+"ay" print(" ".join(str))
A short and simple solution: https://code.sololearn.com/cQ9wZv1ypQwc/?ref=app
I think u can try thi8s method
I'm late to the party but here's my 1 line solution. print(" ".join([w[1:len(w)] + w + "ay" for w in input().split()]))
What does this do? i[1:]
pig_latin = " ".join([(i[1:]+i+"ay") for i in input().split()]) print(pig_latin)