Question from code coach 2d map problem . Kindly help only two test case are correct | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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]))

27th Apr 2020, 9:49 AM
manjeet gupta
manjeet gupta - avatar
2 Answers
+ 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'.
27th Apr 2020, 10:55 AM
Lothar
Lothar - avatar
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.
27th Apr 2020, 11:13 AM
manjeet gupta
manjeet gupta - avatar