FIND SUM OF ALL EVEN AND ODD NUMBERS AND SUBSTRACT THEM IN PYTHON

Code:

l = [12,34,56,78,90,23,34,47,79]

def diff_even_odd_sum(l):
    se = 0
    so = 0
    # YOUR CODE GOES HERE
    for x in l:
        if x % 2 == 0:
            se = se + x
        else:
            so = so + x
    diff = se - so
    return diff

Output:

diff_even_odd_sum(l)

Out[4]:

155

Leave a Reply