-2

The for example is 1,2,3,4,5,6

And I would have to get 1,3,6,10,15,21 By adding the numbers next to each other. I don’t know where to start any help appreciated

Import sys 
For line in sys.stdin print(line end=“”)

1 Answers1

0

simple solution would be:

sum_cons = [1,2,3,4,5,6]
sums_res = []
curr_sum = 0
for num in sum_cons:
    curr_sum += num
    sums_res.append(curr_sum)
print(sums_res)

Outputs:

[1, 3, 6, 10, 15, 21]
David Meu
  • 1,527
  • 9
  • 14