1
I need to sum up all the possible values within one array to find out where an error is in a database.
Code until then:
valores = [50.70,1.80,121.37,100.00,3887.42,248.17,5650.31,702.00,556.90,54.77,2612.55,2414.05,1077.80,2612.55,47.90,535.56,1157.83,3116.31,250.00,780.00,1799.26,1732.09,2468.94,2612.55,715.50,550.00,600.00,890.52,1714.31,1714.61,150.35,2499.70,477.00,90.00,100.00,2412.12,3348.36,2612.55,47.00]
getValor = 0
soma = []
while getValor <= len(valores):
soma[getValor] = valores[getValor] + valores[0]
getValor = getValor + 1
print(soma[getValor])
I would repeat that loop for each value within the array, changing the valores[0]
for valores[1]
and so on. This code returns the error:
Indexerror: list index out of range
How do I do it? How wrong is my logic?
soma
was declared as an empty list, so dolista[0]
already returns this error. Maybe what you are looking for is the functionappend()
, to add a value at the bottom of the list. Anyway, try usingfor
in place ofwhile
, implementation is much simpler.– AlexCiuffa