missing a step.
Yesterday I tried to solve this problem Given a range of numbers. Iterate from first number to the end number and print the sum of the current number and previous number. x =[x for x in range(0,20,2)] for y in x: if y == 0: print(0) else: print(2*y-2) It work but only if you know the interval between the number and if it is constant. So I tried to find a way to check for calculating and checking the interval in a list I used a for loop for y in x: d = x[y] - x[-1] and an if/else to check that d was equal to the value on the first step. It was working fine for a list without step (0,1,2,3,4), but not at all if there was any step. With a step of two only half the element of the list where compared. Took me one hour to figure out that x[y] was not the value of x for the element y, but the value of x at the indice y. So in the case of an odd list : [0,2,4,6] for iteration I had 0 4 that is x[2] and a message error because x[4] does not exist. Finding the source of the error was a lot of fun, because I had to write many variation of my code to understand where was the issue. I ended up understanding that I had to use enumarte and that was the final code. x =[0,1,2,3,5,9,-5] c = x[1] - x[0] print(x) print(f"First step is {c}") for i,j in enumerate(x): if i > 0: d = x[i]-x[i-1] else: d =c if d != c: print(f"none regular step between {i-1} and {i}, the step is {d}")