Reputation: 1589
I was trying to construct a matrix using Python 3.6.0 and in this program, while running it, I encountered a type error which stated that 'type' object is not subscriptable.
#Matrix
x=int(input("Enter number of rows of matrix: "))
y=int(input("Enter number of columns of matrix: "))
for i in range(x-1):
for j in range(y-1):
list[i][j]=int(input("Enter the elements of the matrix row-wise: "))
print(list)
What does this message in the output mean?
What wrong did I do and how should I correct it?
Upvotes: 0
Views: 175
Reputation: 1041
Don't call your variable "list". That's a reserved word.
You should instantiate a list like so
my_list = []
for i in range(0,3):
my_list.append([])
for j in range(0,3):
my_list[i].append(int(input('enter cell value')))
That gives
enter cell value1
enter cell value1
enter cell value1
enter cell value1
enter cell value1
enter cell value1
enter cell value1
enter cell value1
enter cell value1
>>> my_list
[[1, 1, 1], [1, 1, 1], [1, 1, 1]]
Upvotes: 1