I'm just beginning and I do not understand why the error I get when executing is due. I want the for
loop to scroll through the longitudpista
list and compare it to the value of horzpart
and determine, with the conditionals, what value to assign to the variable x
.
def interpolar(x,xconocido1,xconocido2,yconocido1,yconocido2):
interp=yconocido2-(((xconocido2-x)/(xconocido2-xconocido1))*(yconocido2-yconocido1))
return interp
longitudpista = [[0.0,60.0],[61.0,120.0],[121.0,180.0],[181.0,300.0],[301.0,460.0],[461.0,610.0],[611.0,760.0],[761.0,1070.0],1071]
lista1=[[0.0,0.4],[0.4,0.51],[0.51,0.56],[0.56,0.67],[0.67,0.75],[0.75,0.8],[0.8,0.84],[0.84,0.87],[0.87,0.94]]
horzpart = 100
for valor in range(len(longitudpista)):
if horzpart>1071.0:
x=lista1[len(longitudpista)-1][1]
elif horzpart == longitudpista[valor][0]:
x=lista1[valor][0]
elif horzpart == longitudpista[valor][1]:
x=lista1[valor][1]
else:
x=interpolar(horzpart,longitudpista[valor][0],longitudpista[valor][1],lista1[valor][0],lista1[valor][1])
print x
Traceback (most recent call last): File "C: \ Users \ Alexx \ Desktop \ Python \ tests.py", line 13, in elif horzpart == lengthpath [value] [0]: TypeError: 'int' object has no attribute ' getitem ' [Finished in 0.1s]