0
Question from code coach 2d map problem . Kindly help only two test case are correct
x=input().split(",") li=[] for i in x: if "p" in i: ind=list(i).index("p") row=x.index(i) li.append(row) li.append(ind) else: continue print(abs(li[0]-li[2])+abs(li[1]-li[3]))
2 Respuestas
+ 3
If i test it with: XXXXX,XXXXX,XXXXX,XXXXX,XPXXP, I get a 'list index out of range' generated from the print statement. If you look to the var 'li', you can see that in this case only 2 elements are present in 'li'.May be this can help you to check what is going wrong in the code.
An other issue could be that you use lower case to check for 'p'. The task description shows all letters in the map as upper case 'P'.
0
I have changed it to the upper case "P" but still for XPXXP i am unable to get 4 element what should be logic to solve only such case because rest of case i am able to solve.