How to sum values coming from a for?

-2

So, I need to solve a little problem in my code (I'm very newb), I'm just programming because I need this for my TCC, I do not know much about python but I'm trying to turn around.

In line 126 it has that formula del_Frs_uth .... and it returns me several values, since I have several values of Alpha_e that are calculated according to a formula that receives values of a "for structure", where this structure is in question (line 102) depends on some more "for" structures above ... How would I add all values of del_Frs_uth ???

EDIT:Idecidedtocreateanexampletosimplifythequestion,below

K=5N=2L=5del_a=1.5del_b=0.5del_c=0.01foriinrange(1,K+1,1):a=i*del_aforkinrange(1,N+1,1):b=a+(k-1)*del_bforjinrange(1,L+1,1):c=j*del_cd=b-cprint(d)#COMOSOMAROSVALORESDE"d"???

Is there a function that adds values to a vector? how would I store the values of "d" in a vector ?? Thank you all

    
asked by anonymous 05.05.2018 / 22:58

1 answer

0

I do not understand if you want the sum of all d or if you want an array with all d , res_soma will contain the sum and res_array will contain all elements

K = 5
N = 2
L = 5
del_a = 1.5
del_b = 0.5
del_c = 0.01
res_soma = 0
res_array = []

for i in range(1, K + 1, 1):
    a = i*del_a

    for k in range(1, N + 1, 1):
        b = a + (k-1)*del_b

        for j in range(1, L + 1, 1):
            c = j*del_c
            d = b - c
            res_soma += d
            res_array.insert(len(res_array), d)

print(res_array) #[1.49, 1.48, 1.47, 1.46, 1.45, ...
print(res_soma) #235.99999999999997
    
06.05.2018 / 15:41