---
title: "Write a program to find the sum of all even numbers in a list of integers."  
description: "Write a program to find the sum of all even numbers in a list of integers."  
author: "Steilla Mitchel"  
published: 2023-06-18  
updated: 2023-06-19  
canonical: https://www.mindstick.com/forum/158762/write-a-program-to-find-the-sum-of-all-even-numbers-in-a-list-of-integers  
category: "python"  
tags: ["python", "programs"]  
reading_time: 2 minutes  

---

# Write a program to find the sum of all even numbers in a list of integers.

Write a [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) to find the [sum](https://www.mindstick.com/forum/159332/how-can-i-use-sum-in-linq) of all even numbers in a list of integers.

## Replies

### Reply by Aryan Kumar

Sure, here is a Python program to find the sum of all even numbers in a list of integers:

Python

```plaintext
def sum_of_even_numbers(numbers):
  """
  Finds the sum of all even numbers in a list of integers.

  Args:
    numbers: The list of integers to find the sum of even numbers in.

  Returns:
    The sum of all even numbers in the list.
  """

  sum_of_even_numbers = 0
  for number in numbers:
    if number % 2 == 0:
      sum_of_even_numbers += number

  return sum_of_even_numbers

if __name__ == "__main__":
  numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  sum_of_even_numbers = sum_of_even_numbers(numbers)
  print(sum_of_even_numbers)
```

This program works by first initializing a variable called `sum_of_even_numbers` to 0. Then, the program iterates through the numbers in the list and checks if the number is even. If the number is even, then the program adds the number to `sum_of_even_numbers`. Finally, the program returns `sum_of_even_numbers`.

To run the program, you can save it as a Python file and then run it from the command line. For example, if you save the program as `sum_of_even_numbers.py`, you can run it by typing the following command into the command line:

Code snippet

```plaintext
python sum_of_even_numbers.py
```

This will print the sum of all even numbers in the list to the console.

Here is an example of the output of the program:

Code snippet

```plaintext
$ python sum_of_even_numbers.py
30
```

As you can see, the output of the program is 30, which is the sum of all even numbers in the list [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].


---

Original Source: https://www.mindstick.com/forum/158762/write-a-program-to-find-the-sum-of-all-even-numbers-in-a-list-of-integers

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
