In [1]:
# Input
lst = [7,5,4,4,3,1,-2,-3,-5,-7]
In [2]:
# Method 1 - Using a for loop
total = 0
for i in reversed(lst):
if i > 0:
break
total += i
print(total)
In [3]:
# Method 2 - Using a while loop
total1 = 0
j = 1
while True:
total1 += lst[-j]
j += 1
if lst[-j] > 0:
break
print(total1)