0

I don't know where i am getting wrong . Kindly support

x=input().split(",") li=[] def same_def(sme): q=[] for j in range(len(sme)): if "P" in sme[j]: q.append(j) return q for i in x: if (i.count("P")>1) and ("P" in i): li=same_def(i) print(abs(li[0] - li[1])) break elif ("P" in i) and (i.count("P")==1): ind = list(i).index("P") row = x.index(i) li.append(row) li.append(ind) if len(li)==4: print(abs(li[0] - li[2]) + abs(li[1] - li[3]))

29th Apr 2020, 9:39 AM
manjeet gupta
manjeet gupta - avatar
13 Answers
+ 6
The issue in the code is, that you are not detecting all "P" in some special cases. If "P" is in different rows, you can find them without problems. If the input is "XXXXX,XXXXX,XXXXX,XXXXX,XPXXP", both "P" are in the same row, but you only iterate once on each row. So you can find only one "P" in the sample data. Your list "li" should finally contain 4 values. But this is not true in the case i mentioned. Using the above input sample, list "li" only contains 2 values. So you have build a special case for this, and so the code will run without error. But it would be better, as you now know the issue, if you can modify the way you check the input data.
29th Apr 2020, 10:35 AM
Lothar
Lothar - avatar
+ 4
When you say that you are getting wrong, does it mean that your code does fail in code coach? If yes - do they show the error or is it a hidden test case? BTW, i have seen the the task description, as i also have done this code.
29th Apr 2020, 11:42 AM
Lothar
Lothar - avatar
+ 4
How many test cases do you fail? Open ones, hidden ones? And you are sure you have placed the last version of your code in code coach?
29th Apr 2020, 12:09 PM
Lothar
Lothar - avatar
29th Apr 2020, 9:59 AM
manjeet gupta
manjeet gupta - avatar
0
Swim the above code is related to this querry
29th Apr 2020, 9:59 AM
manjeet gupta
manjeet gupta - avatar
0
With respect to input example you have given 1st if statement just below for loop will do work . Their li is getting two element for example that you have posted. I still don't understand where i am getting wrong
29th Apr 2020, 10:54 AM
manjeet gupta
manjeet gupta - avatar
0
I have defined written two li statement one is for 4 element n one is for 2 element .
29th Apr 2020, 10:56 AM
manjeet gupta
manjeet gupta - avatar
0
They are showing hidden test case. That's why i am unable to check where i am getting wrong i have tried many inputs . N working well in python interpreter.
29th Apr 2020, 11:45 AM
manjeet gupta
manjeet gupta - avatar
0
Yes. I am sure about version. Hiden ones 2 case . I am failing
29th Apr 2020, 12:27 PM
manjeet gupta
manjeet gupta - avatar
0
Could someone please paste the text of the taak into a comment. I'd really like to help here.
30th Apr 2020, 5:21 PM
Electron
Electron - avatar
- 2
Kindly visit link to understand
29th Apr 2020, 9:59 AM
manjeet gupta
manjeet gupta - avatar