0
Python challenge output
below code prints output value of sum as 18... could you please explain it to me ? b = [0,1,2,3,4,5] sum = 0 for n in b : sum += n if n == 3 : b.insert(n,10) if sum > 15: break print (sum) print (b)
3 Answers
+ 3
10 is inserted at position 3, but then the loop goes on with index 4, where 3 is sitting now, so it will be added again.
1+2+3+3+4+5=18
+ 1
deleted duplicate entry.... expecting explanation of code output from any1
+ 1
oh...I got it now.. looking after your result...thanks...
I missed that sum is updated before updating list...