def sum_of_evens(lst):
second_negative_index = next(i for i, x in enumerate(lst) if x < 0)[1]
sum = 0
for i in range(second_negative_index + 1, len(lst)):
if lst[i] % 2 == 0:
sum += lst[i]
return sum
input_str = input()
numbers = [int(num) for num in input_str.split()]
print(sum_of_evens(numbers))
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
def sum_of_evens(lst):
second_negative_index = next(i for i, x in enumerate(lst) if x < 0)[1]
sum = 0
for i in range(second_negative_index + 1, len(lst)):
if lst[i] % 2 == 0:
sum += lst[i]
return sum
input_str = input()
numbers = [int(num) for num in input_str.split()]
print(sum_of_evens(numbers))