fork download
  1. def rec_cumsum(numbers):
  2. ''' Input: numbers - a list of numbers,
  3. Output: a list of cumulative sums of the numbers'''
  4. new_list=numbers
  5. last=new_list[-1]
  6. if numbers==[]:
  7. return numbers
  8. if len(numbers) == 1:
  9. return numbers[0]
  10. new_list.remove(last)
  11. rec= rec_cumsum(new_list)
  12. new_list.append(rec+last)
  13. return last+rec
  14.  
  15. tests = [[],
  16. [1],
  17. [1,2],
  18. [1,2,3],
  19. [1,2,1,3],
  20. ]
  21. for t in tests:
  22. print(rec_cumsum(t))
  23.  
Runtime error #stdin #stdout 0.09s 10872KB
stdin
Standard input is empty
stdout
Standard output is empty