# D. Scott # CCI - Problem 1.8 # For any 0 value in an M x N matrix, zero out that column and row M = input("How many rows (M) will your matrix have? ") N = input("How many columns (N) will your matrix have? ") count = 0 matrix = [] row = [] rows = [] cols = [] while (count < int(M)*int(N)): n=input("Enter an integer: ") row.append(int(n)) count += 1 if (count != 0 and count % int(N) == 0): matrix.append(row) row = [] for i in range(0,int(M)): print(matrix[i]) for i in range(0,int(M)): for j in range(0,int(N)): if (matrix[i][j] == 0): rows.append(i) cols.append(j) for r in rows: for i in range(0,int(N)): matrix[r][i] = 0 for c in cols: for i in range(0,int(M)): matrix[i][c] = 0 print("\nZero Matrix:") for i in range(0,int(M)): print(matrix[i]) # D. Scott # CCI - Problem 1.8 # For any 0 value in an M x N matrix, zero out that column and row M = input("How many rows (M) will your matrix have? ") N = input("How many columns (N) will your matrix have? ") count = 0 matrix = [] row = [] rows = [] cols = [] while (count < int(M)*int(N)): n=input("Enter an integer: ") row.append(int(n)) count += 1 if (count != 0 and count % int(N) == 0): matrix.append(row) row = [] for i in range(0,int(M)): print(matrix[i]) for i in range(0,int(M)): for j in range(0,int(N)): if (matrix[i][j] == 0): rows.append(i) cols.append(j) for r in rows: for i in range(0,int(N)): matrix[r][i] = 0 for c in cols: for i in range(0,int(M)): matrix[i][c] = 0 print("\nZero Matrix:") for i in range(0,int(M)): print(matrix[i])