0
Can any body help me know why this adds 3multiple times instead of adding 10
a = [0,1,2,3,4,5] S=0 for n in a: S += n if(n==3): a.insert(n,10) if(S>15): break Print(s)
2 odpowiedzi
+ 3
Because whenever n is 3, a 10 is inserted at the spot where 3 is.
Which means that 3 shifts one slot to the right.
Which means that in the next loop we'll meet that 3 again.
+ 1
Thanks HonFu