ich versuche diesen Code zu verbessern. So wie das ist, funktioniert nicht, weil man am Ende für manche "condicion" ein Element abziehen soll. Dann hatte ich die Idee für die if-Bedingung ein Element im Voraus zu addieren.
Code: Alles auswählen
lista = [33, 42, 10, 13, 19, 82, 32, 14, 17, 29, 19, 24, 4, 79, 33, 13, 38, 6]
condicion = 89
resultado = []
for elemento in lista[::2]:
# rel_2 = sum(resultado) + elemento
# if rel_2 >= condicion:
if sum(resultado) >= condicion:
break
else:
resultado.append(elemento)
print(sum(resultado[:-1]))