Convert list to array python without numpy
Ngày đăng:
08/12/2021
Trả lời:
0
Lượt xem:
51
I can use this code to check if a row in a matrix = x: q = [[1,2,1],[1,2,1],[2,1,2]] answer = [sum(row) for row in q] for i in range(0, len(q)): if answer[i] == 6: print "Player 2 won!" if answer[i] == 3: print "Player 1 won!" if answer[i] != 6 and 3: print "It's a tie!"How can I check if my matrix has a diagonal or column that = x, without using Numpy (Is there a mathematical way to do it as shown above?) Example: (X = something that doesn't matter) q = [[1,X,X],[1,X,X],[1,X,X]] Should print True q = [[1,X,X],[X,1,X],[X,X,1]] Should print True (Diagonal) q = [[X,X,1],[X,1,X],[1,X,X]] Should print True (Diagonal{Other One}) q = [[1,X,X],[X,1,X],[X,1,X]] Should print False q = [[X,1,X],[X,1,X],[X,1,X]] Should print True (Horizontal) How the matrix should have its "winning conditions" |