+ 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)
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)
+ 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)
+ 1
something like that i think