enter code here
"""Write a function that takes a list of numbers and returns the cumulative sum; that is, a new list where the ith element is the sum of the first i + 1 elements from the original list. For example, the cumulative sum of [1, 2, 3] is [1, 3, 6]."""
def list(l):
new_l = []
j = 0
for i in l:
for i in range(l.index(i)+1):
j += l[i]
new_l.append(j) # this for loop seems to accumulate twice
return new_l
print list([1,2,3,4]) # [1,4,10,20] other than [1,3,4,10]
입니다. [1,3,4,10]을 인쇄 해 주셔서 감사합니다! 여기에 루프 -파이썬 기본을위한 코드를 수정하는 데 도움을주십시오. 'for'루프가 누적 합계
나는 [1,3,6,10]을 (를) 의미한다고 생각합니다. –