0
The following code to enter and print a matrix is printing an 'empty' 2D list instead of what I entered. What error am I making?
matrix = [] n = int(input("Enter the dimensions of the square matrix: ")) temp = [] for i in range(n): for j in range(n): temp.append(input(str(i)+str(j)+" ")) matrix.append(temp) temp.clear() print (matrix)
1 Antwort
+ 6
Your temp.clear() empties it which is reflected in matrix. Your temp initialization was in wrong place. Updated here:
https://code.sololearn.com/cuFQfd12wEmz