+ 1
Please help me with an explanation, regarding the answer to this code
4 Antworten
+ 2
1) step
n=1
A[n]=A[1]=0
# output [1,0,3,4,1]
2) step
n=0
A[0]=0
# output [0,0,3,4,1]
3) step
n=3
A[3]=0
#output [0,0,3,0,1]
4) step
n=0
5) step
n=1
#Answer => [0,0,3,0,1]
+ 2
In all cases and for each iteration n will not have the values 2 and 4 so first value of n not altered are 3 and 1 .
n has the value 1 then 0 then 3 then 1 so no A[3] and no A[4] that will keep their initial values
+ 1
#Run this code and see how there changing..
A=[1,2,3,4,1]
for n in A:
print(n, " ",A[n])
A[n]=0
print(A)
#If not clear, give a reply......
+ 1
Put 1,2,.... One by one in
A[n]
in place of n
It will be clear to you.