+ 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
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
+ 3
Hind Biswas well done 🙌
+ 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
+ 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
+ 2
Namit Jain this one is working now:-
https://code.sololearn.com/cXwI6PNEudEg/?ref=app
+ 2
Hind Biswas you didn't acknowledge my code 😭😫
https://code.sololearn.com/cy5AZdpsxNvn/?ref=app
+ 1
♤♢☞ 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 ☜♢♤ but what's the problem in my code?
+ 1
Hind Biswas see my solution! And check if it works
https://code.sololearn.com/cy5AZdpsxNvn/?ref=app
+ 1
Namit Jain yes that's the problem. repeated letters are the problem
0
Remove that .lower()
This will give all correct!
https://code.sololearn.com/cy5AZdpsxNvn/?ref=app
0
♤♢☞ 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 ☜♢♤ ok wait a min
0
Namit Jain I removed the .lower() yet 2 tests failed