Solution Bug for Odd Indices Code Challenge

#loops

There seems to be a bug in the solution check. My code outputs the odd indices, but the check conflictingly requests even numbers, according to its error message:

odd_indices([4, 3, 7, 10, 11, -2]) should have returned [3, 10, -2] , and it returned [3, 7, 11]

10 and -2 are not odd numbers. Suffice to say, I cannot progress to the next section without matching the answer. This was my code:

#Write your function here

def odd_indices(lst):

odd =

for num in lst:

if num % 2 == 1:

  odd.append(num)

return odd

#Uncomment the line below when your function is done

print(odd_indices([4, 3, 7, 10, 11, -2]))

I think that question is looking for odd indices rather than odd numbers. The index refers to the position of the data in a sequence like a string or list starting at 0 and incrementing by 1 every time.

So [4, 3, 7, 10, 11, -2] has 4 at index [0], 3 at index [1], 7 at index [2] and so on. You want the odd index which would be every other value in this case.

3 Likes

In your example you are iterating over the nums in the list, but you should be iterating over its indexes. Hint: Think back to the list lessons where they taught us how to get a value at a specifc index;)