list index out of range

1
Tsup=[]
Te=0
dt=1
t=range(0,3600*2,dt)
r=len(t)
for i in range(0,r):
   Tsup.append(20)
....
   Tsup.append( (((Pj[i]+Ps-Pc[i]-Pr[i])*(dt))/((m_al*c_al[i])+(m_a*c_a[i])))+Tsup[i] )

   if i==r: 
      Te=(((Pj[i]+Ps-Pc[i]-Pr[i])*(dt))/((m_al*c_al[i])+(m_a*c_a[i])))+Tsup[i]

variacao=[]
T_est=0
for i in range(0,l+1):
    variacao.append(abs(Te-Tsup[i]))
    if variacao[i] < 0.1 and variacao[i-1] > 0.1:
       T_est=Tsup[i]

The "list index out of range" error appears on the line varacao.append (abs (Te-Tsup [i])).

    
asked by anonymous 18.02.2016 / 13:36

1 answer

1

First you made a for% of elements% to fill in the r variable. Then, you made a% of elements% for TSup . It is natural to give the error r + 1 . The problem is there. I have not seen your logic, but do you need to loop% elements%? If not, the solution is to only put Tsup[i] instead of list index out of range , as it was placed.

EDIT :

There is a syntax error in the first for. You did not put the colon: at the end of it.

One caution you have to take is about indentation, okay? The second one is unnecessarily indented. The interpreter will complain about this.

    
18.02.2016 / 14:13