Help with Odd Indices code - not iterating through while loop

Hello,

This is the question:

Create a function named odd_indices() that has one parameter named lst .

The function should create a new empty list and add every element from lst that has an odd index. The function should then return this new list.

For example, odd_indices([4, 3, 7, 10, 11, -2]) should return the list [3, 10, -2] .

I wrote the code as below:

I only get [3] as the output, seems like my i isnt iterating even though I have added the i += 1 in the loop. Any help will be appreciated!

Hello @dhayatkarshalaka, welcome to the forums! You return the result inside the while loop. This means that the first iteration where the number is odd, only that number will be appended to the new_list list.

1 Like