我试图得到[1,3,6]作为结果.我错过了一些非常明显的东西吗 我得到的错误是:IndexError: list index out of range
def cumulative_sum(n):
cum_sum = []
y = 0
for i in n:
y += n[i]
cum_sum.append(y)
print cum_sum
a = [1,2,3]
cumulative_sum(a)
Run Code Online (Sandbox Code Playgroud) python ×1