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


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


1234 => 2 + 4

4567 => 4 + 6

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

s = 0


def sumofevendigits(n):
    global s
    if n > 0:
        r = n % 10
        if r % 2 == 0:
            s = s + r
        sumofevendigits(int(n / 10))
    return s


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

s = sumofevendigits(n)

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

Output:

Enter a number:1234
Sum of even digits: 6