Python Program to find the sum of even digits of a number


In this program, You will learn how to find the sum of even digits of a number in Python.


202 = 2 + 2 => 4

1234 = 2 + 4 => 6

Example: How to find the sum of even digits of a number in Python

n = int(input("Enter a number:"))

s = 0
while n > 0:
    r = n % 10
    if r % 2 == 0:
        s = s + r
    n = int(n / 10)

print("Sum of even digits:", s)

Output:

Enter a number:2345
Sum of even digits: 6