I was trying this
n = int(input())
m = int(input())
print(n,m)
for i in range(0,n):
for j in range(0,m):
ar[i][j] = int(input())
for i in range(0,n):
for j in range(0,m):
print (ar[i][j])
But it was showing an error
Traceback (most recent call last):
File "C:/Users/shivansh/Desktop/test.py", line 6, in
ar[i][j] = int(input())
NameError: name 'ar' is not defined
I used to do the same in C language but it works. So, how to this in Python?
解决方案
You haven't declared ar yet. In Python, you don't have to perform separate declaration and initialization; nevertheless, you can't perform operations on names willy-nilly.
Start off with something like this:
ar = [[0 for j in range(m)] for i in range(n)]