Series24. An integer N and a set of N integers containing at least two zeros are given. Output the sum of the numbers from the given set, located between the last two zeros (if the last zeroes are consecutive, then output 0).

Solution in Python 3:

import random

N = random.randrange(5,15)
Z = random.randrange(2,6)

L1 = [random.randrange(1,5) for i in range(0,N)]
L2 = [0 for i in range(0,Z)]
L = L1 + L2

print(L1)
print(L2)
random.shuffle(L)
print(L)

s = 0
for x in L:
if x == 0:
s_last = s
s = 0
else:
s += x

print("Sum = ",s_last)