0
別の部署の代理店に座席を割り当てる必要がありますが、私がしようとするとエラーが発生します。Pythonインデックスエラーが範囲外にある
#matrix for dept1
X = [111, 222, 333, 444, 555, 666, 777 ,888, 999, 123, 234,345]
#matrix for dept2
Y = [1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999,9876, 8765,7654]
#empty class room which consist of 18 students
class_room = [[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0]]
ca = 0
pa = 0
print 'combining dept1 and dept2 in alternative manner'
for i in range(5):
for j in range(25):
if j%2 == 0:
class_room[i][j] = X[pa]
pa += 1
else:
class_room[i][j] = Y[ca]
ca += 1
print class_room
#error - Traceback (most recent call last):
# File "C:\Users\SONY\workspace\mine\taest3.py", line 24, in <module>
# class_room[i][j] = X[pa][pa]
#IndexError: list index out of range
は親切に私が是正とクリアするのに役立つ:私は、コードを貼り付けている下
。
ありがとうございます@Arya McCarthy –
お寄せいただきありがとうございます。これが特に役立った場合は、アップアップすることをお勧めします。 –