def rec_cumsum(numbers):
''' Input: numbers - a list of numbers,
Output: a list of cumulative sums of the numbers'''
new_list=numbers
last=new_list[-1]
if numbers==[]:
return numbers
if len(numbers) == 1:
return numbers[0]
new_list.remove(last)
rec= rec_cumsum(new_list)
new_list.append(rec+last)
return last+rec
tests = [[],
[1],
[1,2],
[1,2,3],
[1,2,1,3],
]
for t in tests:
print(rec_cumsum(t))
ZGVmIHJlY19jdW1zdW0obnVtYmVycyk6CiAgICAnJycgSW5wdXQ6IG51bWJlcnMgLSBhIGxpc3Qgb2YgbnVtYmVycywKICAgICAgICAgICAgT3V0cHV0OiBhIGxpc3Qgb2YgY3VtdWxhdGl2ZSBzdW1zIG9mIHRoZSBudW1iZXJzJycnCiAgICBuZXdfbGlzdD1udW1iZXJzCiAgICBsYXN0PW5ld19saXN0Wy0xXQogICAgaWYgbnVtYmVycz09W106CiAgICAgICAgIHJldHVybiBudW1iZXJzCiAgICBpZiBsZW4obnVtYmVycykgPT0gMToKICAgICAgICAgcmV0dXJuIG51bWJlcnNbMF0KICAgIG5ld19saXN0LnJlbW92ZShsYXN0KQogICAgcmVjPSByZWNfY3Vtc3VtKG5ld19saXN0KQogICAgbmV3X2xpc3QuYXBwZW5kKHJlYytsYXN0KQogICAgcmV0dXJuIGxhc3QrcmVjCiAgICAKdGVzdHMgPSBbW10sCiAgICAgICAgIFsxXSwKICAgICAgICAgWzEsMl0sCiAgICAgICAgIFsxLDIsM10sCiAgICAgICAgIFsxLDIsMSwzXSwKICAgICAgICAgXQpmb3IgdCBpbiB0ZXN0czoKICAgIHByaW50KHJlY19jdW1zdW0odCkpCg==