I want to make a program that takes inputs from the user to build an n x n matrix.
This is what I tried to do:
dim=int(input("Dimension of your matrix? "))
row=[]
matrix=[]
for i in range(dim):
for j in range(dim):
inp=float(input("Insert element with indeces: "+str(i+1)+" "+str(j+1)+" :"))
row.append(inp)
print(row)
matrix.append(row)
row.clear()
print("Your matrix is:")
print(matrix)
And although the printed rows are fine, the final matrix I print consists only of empty lists. It looks something like the following:
[[],[],[]]
Why is this happening?