Below I have the code.
At ex2 and ex3, lst[2] and lst[3] show the different output.
For example:
At ex3, lst[2] shows the output of 5 which is correct but
at ex2, lst[2] shows the output of 4 which is not correct because lst[2] should be added by 2, not by one
Why is that? What did I type wrong? I am new to python so any help would be nice. Thanks
def add_indexes(lst):
for x in range(len(lst)):
if lst[x] == lst[0]:
lst[x] += 0
elif lst[x] == lst[1]:
lst[x] += 1
elif lst[x] == lst[2]:
lst[x] += 2
elif lst[x] == lst[3]:
lst[x] += 3
elif lst[x] == lst[4]:
lst[x] += 4
return lst
ex1 = [0, 0, 0, 0, 0]
ex2 = [1, 2, 3, 4, 5]
ex3 = [5, 4, 3, 2, 1]
print(add_indexes(ex1))
print(add_indexes(ex2))
print(add_indexes(ex3))
lst[x] += x.