Please give me solution of Pig Latin with explanation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please give me solution of Pig Latin with explanation

I tried to solve the Pig Latin problem. but I didn’t understand how to make it right. I made it using very crooked methods. First i make a list with input words, i try to change them to pig latin, but i cant change strings, only add new chars. Then i make the change algorithm inside algorithm what divide words in input. but I think there is another way to do this, but I can’t understand how Ok first i try this: clearWord=input(); pigLatinWords=[""]; n=0; for i in clearWord: if i ==" ": n=n+1; pigLatinWords.append("") else: pigLatinWords[n]=pigLatinWords[n]+i; b=""; for k in pigLatinWords: b=k[0]; k.remove(b); k=k+b; k=k+"ay"; print(k)

16th May 2020, 5:48 PM
DankAvHi
DankAvHi - avatar
11 Answers
+ 2
Junior Show whatever you have tried.
16th May 2020, 5:58 PM
A͢J
A͢J - avatar
+ 1
This could help you Junior PigLatin=input() PigLatin =PigLatin.split() for i in range(len(PigLatin)) : PigLatin[i]=PigLatin[i][1:]+PigLatin[i][0]+"ay" print(" ".join(PigLatin ))
16th May 2020, 6:10 PM
ycsvenom
ycsvenom - avatar
+ 1
for i in input ().split (): print (i [1:] + i [0] + "ay",end=" ") It is shorted method to solve pig latin challange.
17th May 2020, 12:00 PM
Sâñtôsh
Sâñtôsh - avatar
0
Give me link for it
16th May 2020, 5:57 PM
ycsvenom
ycsvenom - avatar
16th May 2020, 5:58 PM
DankAvHi
DankAvHi - avatar
0
Try sharing your code. It’s the best way to learn and we’ll probably spot the issue right away.
16th May 2020, 5:59 PM
Runcible
0
clearWord=input(); pigLatinWords=[""]; n=0; for i in clearWord: if i ==" ": n=n+1; pigLatinWords.append("") else: pigLatinWords[n]=pigLatinWords[n]+i; b=""; for k in pigLatinWords: b=k[0]; k.remove(b); k=k+b; k=k+"ay"; print(k) Ok first i try this
16th May 2020, 6:00 PM
DankAvHi
DankAvHi - avatar
0
I lose second solution
16th May 2020, 6:01 PM
DankAvHi
DankAvHi - avatar
0
YCS-Venom what is split() [i][1:] and .join?
16th May 2020, 6:13 PM
DankAvHi
DankAvHi - avatar
0
Junior Split without any parameters is for splitting string to words list [i] [1:] the first square brackets is for list index And the second is for word index .join is for convert list into string
16th May 2020, 6:17 PM
ycsvenom
ycsvenom - avatar
0
I found another solution pL=input(); plw=[""]; n=0; for i in pL: if i==" ": plw.append(""); n=n+1 else: plw[n]=plw[n]+i; nw=[]; ay=["ay"]; b=[""]; for k in plw: b[0]=k[0]; nw.append(k[1:]) nw=nw+b; nw=nw+ay; nw.append(" "); print("".join(nw))
17th May 2020, 10:04 PM
DankAvHi
DankAvHi - avatar