What does this code?


#1

Can someone plizz explain me this code? I do not understand how it returns 2??

def myst3(A,x):
for r in range(0,len(A)):
for c in range(0,len(A[0])):
if (A[r][c]==x):
return r*c
return 0
print(myst3([[1,2,3],[4,5,6],[7,8,9]],8))



Replace this line with your code.


#2

@arcsurfer86010
Try it with

def myst3(A,x):
    print("range(0,{0})".format(len(A)))
    for r in range(0,len(A)):
        print("r = {0}".format(r))
        if isinstance(A[r], list):
            print("{0}".format(A[r]))
            for c in range(0,len(A[r])):
                print("{0}".format(A[r][c]))
                if A[r][c] == x:
                    print("==> {0}".format(A[r][c]*2))
# if (A[r][c]==x):
# return r*c
# return 0
print(myst3([[1,2,3],[4,5,6],[7,8,9]],8))

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.