TypeError: 'int' object is not subscriptable .....?
TypeError: 'int' object is not subscriptable .....?
if (a % 2 == 0 and b % 2 == 0) or (a % 2 == 0 and b % 3 == 0):
pav=0
pas=1
for i in range(a):
for j in range(b):
if(matrix[i][j]==0 and i+1<=a and j+1<=b):
if(matrix[i][j+1]==0 and matrix[i+1][j]==0):
a[i][j]=a[i][j+1]=a[i+1][j]=pas
pas+=1
pav+=1
if matrix[i+1][j+2]==0:
if(matrix[i][j+2]==0 and matrix[i+1][j+1]==0):
matrix[i+1][j+2]=matrix[i][j+2]=matrix[i+1][j+1]=pas
pas+=1
pav+=1
回溯(最近调用最后):
文件 "C:/Users/Loading/PycharmProjects/Test/test.py",第 14 行,位于
example.check_numbers(矩阵,a,b)
文件 "C:\Users\Loading\PycharmProjects\Test\venv\example.py",第 30 行,在 check_numbers 中
a[i][j]=a[i][j+1]=a[i+1][j]=pas
TypeError: 'int' 对象不可订阅
a[i][j]=a[i][j+1]=a[i+1][j]=pas
这一行。您将 a
视为一个数组,但您显然已将其定义为代码片段之外的整数,因为您正在对它使用模数。
每当您收到错误 object is not subscriptable
时,这意味着您正在尝试将对象视为数组。
if (a % 2 == 0 and b % 2 == 0) or (a % 2 == 0 and b % 3 == 0):
pav=0
pas=1
for i in range(a):
for j in range(b):
if(matrix[i][j]==0 and i+1<=a and j+1<=b):
if(matrix[i][j+1]==0 and matrix[i+1][j]==0):
a[i][j]=a[i][j+1]=a[i+1][j]=pas
pas+=1
pav+=1
if matrix[i+1][j+2]==0:
if(matrix[i][j+2]==0 and matrix[i+1][j+1]==0):
matrix[i+1][j+2]=matrix[i][j+2]=matrix[i+1][j+1]=pas
pas+=1
pav+=1
回溯(最近调用最后):
文件 "C:/Users/Loading/PycharmProjects/Test/test.py",第 14 行,位于 example.check_numbers(矩阵,a,b)
文件 "C:\Users\Loading\PycharmProjects\Test\venv\example.py",第 30 行,在 check_numbers 中 a[i][j]=a[i][j+1]=a[i+1][j]=pas
TypeError: 'int' 对象不可订阅
a[i][j]=a[i][j+1]=a[i+1][j]=pas
这一行。您将 a
视为一个数组,但您显然已将其定义为代码片段之外的整数,因为您正在对它使用模数。
每当您收到错误 object is not subscriptable
时,这意味着您正在尝试将对象视为数组。