I want to take a simple matrix as input in a 2-D array, but get a Runtime Error - NZEC error.
Matrix -
1 2
3 4
my input code -
for i in range(2):
a[i]=[int(i) for i in input().split()]
print(a)
cs95
406k106 gold badges745 silver badges798 bronze badges
asked Aug 3, 2017 at 2:46
Rohit Prakash Singh
1281 silver badge10 bronze badges
1 Answer 1
You are using
ias the loop variable and the list comprehension variable at the same timeYou have not declared
a(visibly). Declarea = []and uselist.append.
Try this:
a = []
for _ in range(2):
a.append([int(i) for i in input().split()])
Declare a to be empty initially. Then call a.append to append new sublists to your list.
answered Aug 3, 2017 at 3:31
cs95
406k106 gold badges745 silver badges798 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py