Commit 193f605d by Bertrand NÉRON

### python2 -> python3

parent 6b129c1d
Pipeline #58672 passed with stages
in 12 seconds
 ... ... @@ -2,7 +2,7 @@ def matrix_maker(ligne, col, val=None): m = [] for i in range(ligne): c = [val]*col c = [val] * col m.append(c) return m ... ... @@ -12,26 +12,27 @@ def matrix_size(m): return len(m), len(m[0]) def matrix_get(matrix, i, j): _check_matindex(matrix,i,j) _check_matindex(matrix, i, j) return matrix[i][j] def matrix_set(matrix, i, j, val): _check_matindex(matrix,i,j) matrix[i][j] = val def matrix_print(m): im, jm = matrix_size(m) for i in range(im): print m[i] def to_str(m): m_str = [] for row in m: m_str.append('\t'.join([str(cell) for cell in row])) m_str = '\n'.join(m_str) return m_str #---- independant regarding matrix structure def _check_matindex(matrix,i,j): imax, jmax = matrix_size(matrix) if (i < 0 or i >= imax) or (j < 0 or j>= jmax): raise IndexError, "matrix index out of range" if (i < 0 or i >= imax) or (j < 0 or j >= jmax): raise IndexError("matrix index out of range") def matrix_get_line(matrix, i): ... ... @@ -41,7 +42,8 @@ def matrix_get_line(matrix, i): for n in range(jm): line.append(matrix_get(matrix, i, n)) return line def matrix_set_line(matrix, i, val): _check_matindex(matrix,i,0) im, jm = matrix_size(matrix) ... ... @@ -56,22 +58,21 @@ def matrix_get_col(matrix, j): for n in range(im): col.append(matrix_get(matrix, n, j)) return col def matrix_set_col(matrix, j, val): _check_matindex(matrix,0,j) im, jm = matrix_size(matrix) for n in range(im): matrix_set(matrix, n, j, val) if __name__ == '__main__': m = matrix_maker(5, 3) matrix_set(m,0, 0, 1) matrix_set(m,0, 2, 2) matrix_set(m,4, 0, 12) matrix_set(m,4, 2, 15) matrix_print(m) print "get line 0", matrix_get_line(m, 0) print "get col 0", matrix_get_col(m, 0) print(to_str(m)) print("get line 0", matrix_get_line(m, 0)) print("get col 0", matrix_get_col(m, 0))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!