Code 98: Tech Mahindra - Odd Even Difference Program | Tech Mahindra Coding | 365 Days of Code

Опубликовано: 15 Январь 2025
на канале: Code House
796
3

Odd Even Difference
Write a program to return the difference between the sum of odd and even numbers from an array of positive integers.

Note:
You are expected to write code in the findOddEvenDifference function only which will receive the first parameter as the number of items in the array and second parameter as the array itself. You are not required to take input from the console

Example:
Finding the difference between the sum of odd even numbers from a list of 5 numbers

Input
5
10 11 7 12 14

Output
-18

Explanation
Sum of Odd - Sum of Even = 18-36 = -18
"""

n = int(input())
num_list = list(map(int, input().split()))

even_sum = 0
odd_sum = 0

for each in num_list:
if each % 2 == 0:
even_sum += each
else:
odd_sum += each

print(odd_sum - even_sum)

Thanks