0
Can anyone explain how this code results in answer 9
x=[0,[2,4,6],[13,11,9]] y=x[2]+x[1]*2 print(y[x[1][0]])
2 Respuestas
+ 12
x is a list :
index 0 = 0
index 1 = [2, 4, 6]
index 2 = [13, 11, 9]
y = x[2] + x[1]*2
= [13, 11, 9] + [2, 4, 6] + [2, 4, 6]
= [13, 11, 9, 2, 4, 6, 2, 4, 6]
Then you have
x[1] = [2,4,6]
so x[1] is a list:
index 0 = 2
index 1 = 4
index 2 = 6
so x[1][0] = index 0 of index 1 of list x = 2
then y[x[1][0]] = y[2] = index 2 of list y = 9.
0
thank you