我不断收到此错误:
line 4, in timesTwo
IndexError: list index out of range
对于这个程序:
def timesTwo(myList):
counter = 0
while (counter <= len(myList)):
if myList[counter] > 0:
myList[counter] = myList[counter]*2
counter = counter + 1
elif (myList[counter] < 0):
myList[counter] = myList[counter]*2
counter = counter + 1
else:
myList[counter] = "zero"
return myList
我不确定如何解决该错误。有任何想法吗?