简体   繁体   中英

How to take a simple integer matrix as input in python3

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)
  1. You are using i as the loop variable and the list comprehension variable at the same time

  2. You have not declared a (visibly). Declare a = [] and use list.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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM