相关疑难解决方法(0)

这个累计金额有什么问题?

我试图得到[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

4
推荐指数
3
解决办法
7341
查看次数

标签 统计

python ×1