I’m trying to get [1,3,6] as the result. Am I missing something really obvious? The error I got is: 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)
Arrays are zero-based in Python, so when you confused
n[i]withi, you were accessingn[3]whilenonly goes from 0 to 2.