Question 1:

To sum a list of numbers, use sum:

xs = [1, 2, 3, 4, 5]
print(sum(xs))

This outputs:

15

Question 2:

So you want (element 0 + element 1) / 2, (element 1 + element 2) / 2, ... etc.

We make two lists: one of every element except the first, and one of every element except the last. Then the averages we want are the averages of each pair taken from the two lists. We use zip to take pairs from two lists.

I assume you want to see decimals in the result, even though your input values are integers. By default, Python does integer division: it discards the remainder. To divide things through all the way, we need to use floating-point numbers. Fortunately, dividing an int by a float will produce a float, so we just use 2.0 for our divisor instead of 2.

Thus:

averages = [(x + y) / 2.0 for (x, y) in zip(my_list[:-1], my_list[1:])]
Answer from Karl Knechtel on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ sum-function-python
sum() function in Python - GeeksforGeeks
November 27, 2025 - The sum() function in Python is used to add up numbers from any iterable such as a list, tuple, set, or dictionary values.
Discussions

Can someone explain to me how to add up all the numbers in a list without using sum?
Use a for loop! Iterate over the list and add each number to the final total More on reddit.com
๐ŸŒ r/learnpython
39
21
June 27, 2022
Sum of Lists (Python)
The way that this is set up, it only matters whether or not the first element is = to a or b. You return immediately after the first element. For instance, this suminout([1,2,3,4,5], 1,1) gives you 13 because it checks the first element (which is equal to a or equal to b), sums all entries (15) and subtracts both a and b (2) and returns that. Perhaps set up your logic like this: Initialize a total variable outside the loop. Add to (or not) this variable inside your if/else. return your variable outside the loop at the end. More on reddit.com
๐ŸŒ r/learnpython
12
1
January 17, 2021
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_sum.asp
Python sum() Function
Remove List Duplicates Reverse ... Study Plan Python Interview Q&A Python Training ... The sum() function returns a number, the sum of all items in an iterable....
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ built-in functions โ€บ sum()
Python | Built-in Functions | sum() | Codecademy
June 20, 2023 - Takes in an iterable object, such as a list or tuple, and returns the sum of all elements.
๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ python โ€บ sum a list of numbers in python
Sum a list of numbers in Python | Sentry
July 3, 2026 - It does this by applying a function (in this case, addition) to the first two items (1 + 2), getting a result (3) and then applying the same function to that result and the next item (3 + 4). This process continues until the list is consumed, ...
Find elsewhere
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-compute-the-sum-of-a-list-in-python
How to compute the sum of a list in python
The sum_of_list function takes ... an example code: ... This is the simplest approach. Python has a built-in sum() function to compute the sum of the list....
๐ŸŒ
University of Vermont
uvm.edu โ€บ ~cbcafier โ€บ cs1210 โ€บ book โ€บ 11_loops โ€บ loops_and_summation.html
Math and Python: loops and summation โ€“ Clayton Cafiero
While we have the Python built-in function sum() which sums the elements of a sequence (provided the elements of the sequence are all of numeric type), itโ€™s instructive to see how we can do this in a loop (in fact, summing in a loop is exactly what the sum() function does).
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-program-to-find-sum-of-elements-in-list
Find sum of elements in List - Python - GeeksforGeeks
Explanation: List comprehension creates a new list identical to a and the sum() function then calculates the total of its elements, storing the result in res. reduce() function from the functools module applies a function (in this case, addition) ...
Published: August 13, 2026
๐ŸŒ
Real Python
realpython.com โ€บ python-sum-function
Python's sum(): The Pythonic Way to Sum Values โ€“ Real Python
March 18, 2026 - This is why Python 2.3 added sum() as a built-in function to provide a Pythonic solution to the summation problem. Alex Martelli contributed the function, which nowadays is the preferred syntax for summing a list of values:
๐ŸŒ
YouTube
youtube.com โ€บ watch
Find Sum Of A List Without Using sum() | Python Example - YouTube
How to find the sum of the numbers in a list in Python without using the built in sum() function. Source code: https://github.com/portfoliocourses/python-ex...
Published: March 31, 2023
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ sum of lists (python)
r/learnpython on Reddit: Sum of Lists (Python)
January 17, 2021 -

In this exercise your function will receive three parameters,

a list of integers, and two integers. It will add up all values

in the list that do not equal either of the two integers.

This is what I have:

def sumniout(nums, a, b):
    for num in nums:
        if num == a or num == b:
            total = sum(nums) - a - b
        else:
            total = sum(nums)
        return total
print(suminout([1,2,3,4], 1,2))       

Example of it working:

suminout([1, 2, 3, 4], 1, 2) -> 7

My code gives me the right results sometimes. For example, if I run a test on print(suminout([1,2,3,4,5], 1,1)) I get 13 when I should get 14. Any ideas to get me on the right track?

๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ python-sum-list
How to use Python to sum a list? | Flexiple Tutorials | Python - Flexiple
March 14, 2022 - As explained, the int value in the string causes the TypeError. Other than this limitation, you can make use of the sum() function in Python with ease for all summing operations.
๐ŸŒ
Centron
centron.de โ€บ home โ€บ tutorials โ€บ python sum() function
Python sum() Function โ€“ centron
May 19, 2026 - Python sum() function is used to get the sum of numbers of an iterable.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ sum_function.htm
Python sum() Function
The Python sum() function returns the sum of all numeric items in any iterable, such as a list or tuple. It also accepts an optional "start" argument which is 0 by default. If given, the numbers in the list are added to the start value.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ sum of elements in the list in python
Sum of Elements in the List in Python - Spark By {Examples}
May 31, 2024 - How to find the sum of elements in the list in Python? To find the sum of elements in a list in Python, you can use the built-in sum() function. There are
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ list โ€บ python-data-type-list-exercise-1.php
Python: Sum all the items in a list - w3resource
June 28, 2025 - This function will be used to calculate the sum of all the numbers in the items list. sum_numbers = 0 -> This line initializes a variable called sum_numbers to zero.
๐ŸŒ
Substack
dailypythonprojects.substack.com โ€บ daily python projects โ€บ python project: function to calculate the sum of a list
Python Project: Function to Calculate the Sum of a List
March 27, 2025 - You can customize the list to test with different sets of numbers. ... Now, call the calculate_sum() function with the list of numbers, and print the result so you can see the total sum.