Skip to main content
  • Python is available now. All other compilers are coming soon.

    Python
  • Popular Tutorials

    • Getting Started With Python
    • Python if Statement
    • while Loop in Python
    • Python Lists
    • Dictionaries in Python
    All Python Tutorials

    Reference Materials

    Built-in FunctionsList MethodsDictionary MethodsString Methods
    View all

Online Compilers

  • Python Compiler
  • Python Playground
  • Python Projects
  • Exercises

Tutorials

  • Learn Python
  • Python for Beginners
  • Variables and Types
  • Python Strings
  • Python Lists
  • Python If Else
  • Python For Loops
  • Python Functions
  • Python Classes

Examples

  • Python Examples
  • Hello World
  • Add Two Numbers
  • Even or Odd
  • Factorial
  • Fibonacci
  • Prime Check
  • Palindrome Check

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Use
  • Disclaimer

© 2026 ILoveCompiler. All rights reserved.

  1. Home
  2. Python Exercises
  3. Sum of Even Numbers

Loops and patterns · Python exercise

Sum of Even Numbers

Read a line of integers and add only the even ones.

beginner3 testslistsconditionssum

Problem

Read one line of space-separated integers and print the sum of those that are even. If there are no even values, print 0.

Input and output

Input
One line of space-separated integers.
Output
A single line containing the sum of the even values.

Constraints

  • The line contains between 1 and 1,000 integers.

Examples

Example 1

Input

1 2 3 4 5 6

Output

12

Example 2

Input

1 3 5

Output

0

How testing works

Your code runs once per test case with that case's standard input. Output is compared after normalising trailing spaces and blank lines at the end. Use input() without a prompt when the exercise expects clean output.

Your solution3 hidden input checks

Loading editor…

Press Run tests to execute your code against every input case. Python runs in a Web Worker in your browser.

Related exercises

beginner

Number Triangle

Print rows of increasing numbers separated by spaces.

3 tests
beginner

Sum a List of Integers

Read a line of space-separated integers, convert them, and print their total.

3 tests
Previous exerciseNumber TriangleNext exerciseReverse a String