+ 2

Python- can someone help me with the logic

arr = [0,1,2,3,4,5] sum = 0 for n in arr: sum = sum + n if (n == 3) arr.insert( n,10) if(sum > 15): break print (sum)

22nd Sep 2018, 12:58 PM
AMAN TOMAR
AMAN TOMAR - avatar
3 Antworten
+ 5
Run this code and you will see. Adding prints often helps. arr = [0,1,2,3,4,5] sum = 0 for n in arr: sum = sum + n print(arr,sum) if (n == 3): arr.insert( n,10) if(sum > 15): break print (sum)
22nd Sep 2018, 1:14 PM
davy hermans
davy hermans - avatar
+ 1
arr = [0,1,2,3,4,5] sum = 0 for n in arr: sum = sum + n if n ==(arr[5]): arr.insert( n,10) if(sum > 15): break print (sum)
23rd Sep 2018, 11:20 AM
Misha
+ 1
something like that i think
23rd Sep 2018, 11:21 AM
Misha