Could someone tell me why my if statement is skipped (doesn’t enter the nest) once I return back to it on the 3rd time of the loop? (I know there are other problems with this code but I want to solve this one first.)
def almostIncreasingSequence(sequence):
failure = 0
list_index = 0
post_index = 1
while failure < 2:
max_length = len(sequence)
if sequence[list_index] < sequence[post_index] and post_index <= max_length and failure < 2:
list_index += 1
post_index += 1
if post_index >= len(sequence):
return True
elif sequence[list_index] > sequence[post_index] and post_index <= max_length and failure < 2:
failure += 1
sequence.pop(list_index)
post_index = 0
list_index = 1
else:
return False
sequence = [1, 3, 2]
almostIncreasingSequence(sequence)