+ 1

What is the problem in this code?

#Code Coach: Pig latin In the following code, 3 of 5 tests are successful but 2 hidden tests are failed. Where is the problem?? --->Code:- x = input().split(" ") o = "" for i in x: o = o + i.replace((i[0]), "") + i[0] +"ay " print (o) https://code.sololearn.com/cXwI6PNEudEg/?ref=app https://code.sololearn.com/cXwI6PNEudEg/?ref=app

26th Aug 2020, 12:29 PM
Hind Biswas
Hind Biswas - avatar
14 Respuestas
+ 2
Try to enter words having the first letter repeated twice! For example: namitjain is a good person expected: amitjainnay siay aay oodgay ersonpay output: amitjainay siay aay oodgay ersonpay .replace function replaces all occurances of the the input value Here for the first word: i = "namitjain" i = i.replace(i[0],"") # i[0] is "n" print(i) output is amitjai instead of amitjain
26th Aug 2020, 12:58 PM
Namit Jain
Namit Jain - avatar
+ 3
Hind Biswas well done 🙌
26th Aug 2020, 1:13 PM
Namit Jain
Namit Jain - avatar
+ 3
Namit Jain I did acknowledged your code. I used that i[1:] + I[0] from your code.... Thanks a lot.... I just wanted to try something new by myself.... AGAIN, thanks a lot
26th Aug 2020, 1:17 PM
Hind Biswas
Hind Biswas - avatar
+ 2
♤♢☞ 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 ☜♢♤ It's explained below: x = input().split(" ") # above code splits the input and makes a list #example: input= hello world #it'll create a list x = ['hello', 'world'] o = "" # 'o' is an empty variable which will store the output for i in x: # the for loop is to go through each word in 'x' o = o + i.replace((i[0]), "") + i[0] +"ay " #Here, in each iteration of the loop, by "i.replace((i[0]), "")" the 1st letter is replaced by empty string and by "+ i[0]" code, the first letter is added at the last of the word. "+ "ay "" code adds ay after that first letter. #Then, "o = o + ...." appends the word to the variable o. #Example: #1st iteration: hello -> ello -> elloh -> ellohay #This ellohay is appended in o variable. #next iteration: world -> orld -> orldw -> orldway #This is again appended to o. #So at last the value of o = "ellohay orldway" print (o) #This prints out the final value of o
26th Aug 2020, 12:57 PM
Hind Biswas
Hind Biswas - avatar
26th Aug 2020, 1:11 PM
Hind Biswas
Hind Biswas - avatar
+ 2
Hind Biswas you didn't acknowledge my code 😭😫 https://code.sololearn.com/cy5AZdpsxNvn/?ref=app
26th Aug 2020, 1:12 PM
Namit Jain
Namit Jain - avatar
26th Aug 2020, 12:41 PM
Hind Biswas
Hind Biswas - avatar
+ 1
Hind Biswas see my solution! And check if it works https://code.sololearn.com/cy5AZdpsxNvn/?ref=app
26th Aug 2020, 12:50 PM
Namit Jain
Namit Jain - avatar
+ 1
Namit Jain yes that's the problem. repeated letters are the problem
26th Aug 2020, 1:05 PM
Hind Biswas
Hind Biswas - avatar
0
Remove that .lower() This will give all correct! https://code.sololearn.com/cy5AZdpsxNvn/?ref=app
26th Aug 2020, 12:41 PM
Namit Jain
Namit Jain - avatar
26th Aug 2020, 12:43 PM
Hind Biswas
Hind Biswas - avatar
0
Namit Jain I removed the .lower() yet 2 tests failed
26th Aug 2020, 12:44 PM
Hind Biswas
Hind Biswas - avatar