Write a Python function, the syntax is ReplaceMe(input)
Where input is a list of numbers and this function would replace each element with its running sum. The following example would give some idea.
Let 1,2,3,4 is the list output would be 1,3,6,10. Do not use any library functions, use loops and other basic structures.
def solve(nums):
n = len(nums)
rs = [nums[0]]
#sauravhathi
for i in range(1, n):
nums[i] += nums[i-1]
#sauravhathi
rs.append(nums[i])
return rs
nums = [1, 2, 3, 4]
print(solve(nums))
Output:
[1, 3, 6, 10]
Happy Learning – If you require any further information, feel free to contact me.