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)
11 Respostas
+ 2
Junior Show whatever you have tried.
+ 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 ))
+ 1
for i in input ().split ():
print (i [1:] + i [0] + "ay",end=" ")
It is shorted method to solve pig latin challange.
0
Give me link for it
0
Try sharing your code. Itâs the best way to learn and weâll probably spot the issue right away.
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
0
I lose second solution
0
YCS-Venom what is split() [i][1:] and .join?
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
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))