Calculating running total with the walrus operator

Report a typo

Your task is to write a function running_total to calculate the running total of a list of numbers. The function should return a list where each element is the sum of the numbers seen so far. Utilize the Walrus Operator to streamline your code.

The Walrus Operator (:=) can be effectively used to update the running total while iterating through the list. This way, you can both calculate the new total and append it to the result list in a single line.

Sample Input 1:

1 2 3 4 5

Sample Output 1:

1 3 6 10 15
Write a program in Python 3
def running_total(numbers):
pass

# Input processing
input_numbers = list(map(int, input().split()))
print(*running_total(input_numbers))

Create a free account to access the full topic