Im trying to iterate over my list and calculate the diff between each element and the element following it. If the difference is greater than 0 ( or positive ) then increment up and decrease down by 1 ( if it is greater than 0 ). Similarly if difference is less than 0 then increment down and decrease up by 1 ( if greater than 0 ) . I want to exit out of the loop if either the up or down exceeds limit which is set to 3.
My code:
my_list = [13.04, 12.46, 13.1, 13.43, 13.76, 13.23, 12.15, 12.0, 11.55, 14.63]
up = 0
down = 0
limit = 3
while (up < limit) or (down < limit) :
for i in range(len(my_list)-1):
diff = my_list[i] - my_list[i+1]
print (diff)
if diff > 0:
up +=1
if down > 0:
down -=1
elif diff < 0:
down +=1
if up > 0:
up -=1
Obviously this is not working since I keep getting caught up in an infinite loop and cant figure out what I am doing wrong.