I am trying to write a python function that returns the indices of all even numbers in a list. However, it is only returning the index of the first even number.
My code
def indicesOfEvens(listOfInt):
"""return list with indices (indexes) of each even int
if no even ints in the list, return an empty list
if listOfInt isn't a list, or has something that isn't an int,
raise ValueError
"""
if (type(listOfInt) != list):
raise ValueError("must be list")
for item in listOfInt:
if (type(item) != int):
raise ValueError("must be list of ints")
index= []
for i in range(0,len(listOfInt)):
if listOfInt[i] % 2 == 0:
return index + listOfInt[i]
return index
Test Case
def test_indicesOfEvens_1():
assert indicesOfEvens([11,20,35,44,57,63,42])==[1,3,6]