python - creating function guess_index -
Creating a function estimate_ index, which tells where the number on the board is so if I have a 4x4 board, then the numbers
[[2, false], [3, false], [4, false], [1, false] [same row as above [above] as the above line ] [/ Code> So, first I need to change it to a list like below
[[0,1,2,3], [4] , 5,6,7], [8 9, 10, 11], [12,13,14,15]] So estimate_index (board, 3) [0,3 ] Back Should meaning that No. 3 is located at 0 th row; The third column should also be returned to the estimate_index (board, 14) [3,2] The hard part is working for 2x4 vs a 4x2 matrix etc.
My code is
DFF estimates (board, estimation) for count = 0 I in board: i in j: board [i] [j] == [count] in the board for count = 1: for b: a: If b == estimate: return [a, b] But when I try the examples written above, even then I can not find any ??
Start with:
board = [[[5, False], [5, false], [3, false], [4, false]] [[1, false] [0, false], [6, false], [7, false]], [[2] , [False], [2, false], [3, false], [0, false]], [[7, false], [6, false], [1, false], [4, false]] < / Code> You can:
def guess_index (board, estimate): "" "Calculate coordinates for the approximate index within the board" " "Row_len = len (board [0]) guess back / line_lan, say% row_len example:
& gt; & Gt; & Gt; Estimate_index (board, 3) (0, 3) & gt; & Gt; & Gt; You can use it to get an integer and boolean value from board estimate_index (board, 14) (3, 2) east > line, col = estimate_index (board, estimate) int_value, bool_value = board [row] [col] in the case estimate == 3 will be int_value == 4 and bool_value == incorrect .
Comments
Post a Comment