How can I get the sum of all values in a list?


#1

Question

In the context of this code challenge, how can I get the sum of all values in a list?

Answer

One way to get the sum of all the values in a list is to utilize the built-in sum() function in Python. This function will take in a list of numerical values, and return the total of all the values.

Another way to sum all values in a list, is to utilize a loop which iterates over every value, and keeps a running total of all the values.

In this code challenge, consider implementing the second method using a loop to sum the values, instead of the first method of using the sum() function.