每天一习题,提升Python不是问题!!有更简洁的写法请评论告知我!
https://www.cnblogs.com/poloyy/category/1676599.html
请写一个函数,该函数 参数为数字列表,请算出另外一个列表,里面每个元素依次是参数列表里面元素的累计和。
比如 参数为[1, 2, 3, 4]
结果计算方法为[1, 1 + 2, 1 + 2 + 3, 1 + 2 + 3 + 4]
返回结果就应该是[1, 3, 6, 10]
def count_test(lists):
res = []
lens = len(lists)
for i in range(0, lens):
res.append(lists[i])
for j in range(0, i):
res[i] += lists[j]
print(res)
lists = [1, 2, 3, 4]
count_test(lists)