I am new in python and I don't know why this program is not updating the 'i' variable when I am incrementing it in the execution of for loop.
len(a) = 10
you can see in the code that I am incrementing 'i' time after time but after the increment when I comes into loop iteration it nullifies the update made in the body of loop. Why is this is ? It should be updated in general and loop execution should be less than 10. Please help.
final_result = 0
a= '3 4 4 5 6'
for i in range(0,len(a)):
print('iteration')
print('i is = ')
print(i)
if a[i] is ' ' and a[i+1] is not ' ':
if i-1 is 0:
final_result = int(a[i-1]) + int(a[i+1])
i += 2 //here goes the increment
print('1a- m here')
print(final_result)
print('i is = ')
print(i)
else:
final_result = final_result + int(a[i+1])
i += 2 //here goes the increment
print('1b- m here')
print(final_result)
elif a[i] is ' ' and a[i+1] is ' ':
if i-1 is 0:
final_result = int(a[i-1]) - int(a[i+1])
i += 3 //here goes the increment
print('2a- m here')
print(final_result)
else:
final_result = final_result - int(a[i+2])
i += 3 //here goes the increment
print('2b- m here')
print(final_result)
print('i is = ')
print(i)
print(final_result)
itakes up the next value from the list returned by therangewhileloops for these purposes as the increment are conditional