这是为啥呢
我感觉i-1在索引范围内呀
求指点
开始以为是其他地方写错了导致的索引错误,改了好多次都是超出索引范围,撑不住了。
def lastOne(num):
lst = list(range(1, num+1))
while num >= 0:
num = num - 1
if lst[num]%3 == 0:
lst.pop(num)
return lst
if __name__ == "__main__":
lst = lastOne(50)
print(lst)
[1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29, 31, 32, 34, 35, 37, 38, 40, 41, 43, 44, 46, 47, 49, 50]