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]))
13 Antworten
+ 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.
+ 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.
+ 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?
0
Swim the above code is related to this querry
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
0
I have defined written two li statement one is for 4 element n one is for 2 element .
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.
0
Yes. I am sure about version.
Hiden ones 2 case . I am failing
0
Could someone please paste the text of the taak into a comment.
I'd really like to help here.
- 2
Kindly visit link to understand