I am new to python and am having problems seeing why this code does not work. I would like it to return [10,122,2].
close = [5000,5010,5132,5134]
def difference():
x = 0
data = []
while x < len(close):
diff = close[x+1]-close[x]
data.append(diff)
x = x + 1
return data
it returns "IndexError: list index out of range" but my understanding was that the while loop only runs when the condition is met. What am I missing? Thanks