I'm having some trouble getting a piece of software to run. What I am required to do is take an input of numbers and tell if they are increasing or decreasing, starting with an interval of one, meaning that if the list was [13,15,17,15,18]
the first set would be [13,15]
, then [15,17]
, and finally [15,18]
. The first interval section works perfectly fine, but when I increase a
to 2
to try and increase the step of the range function it outputs the same groups as when a
is 1
. The correct outputs when a = 2
should be [13,17]
,[17,18]
,[15,15]
. If I copy paste it and replace the variable a with two, the program does run however it gives me an incorrect number of increases and decreases. I'm sure I'm overlooking something simple, but I've stared at this problem so long that it's gotten freaky. I didn't include all my code, but prod_list is just a list of integers that are all greater than zero.
a = 1
for i in range(0,len(prod_list),a):
while(i-1 < 0):
i +=1
while(i > len(prod_list)):
i -= 1
if(prev != (prod_list[i-1],prod_list[i])):
if((prod_list[i-1] - prod_list[i]) > 0):
decr += 1
elif((prod_list[i-1] - prod_list[i]) < 0):
incr += 1
elif((prod_list[i-1] == prod_list[i]) < 0):
same += 1
print(prod_list[i-1],prod_list[i])
prev = (prod_list[i-1],prod_list[i])
a += 1