Home Task 2 Write a definition of function sum(A,n) which takes an array of ints A and its logical size n and returns the sum of all of the integers in the array code example
Example 1: you are given an array of integers. your task is to print the sum of numbers that occurs for an even number of times in the array.
import collections
def fun(arr):
mp = collections.defaultdict(int)
for i in range(len(arr)):
mp[arr[i]] += 1
sum = 0
for i in mp.keys():
if (mp[i] % 2 == 0):
sum += i
return sum
n= int(input())
arr = list(map(int,input().split()))
print(fun(arr))
Example 2: Write a function that takes an array of number values and returns the sum.
function amountTotal(amount) {
var total = 0;
for (i = 0; i < amount.length; ++i) {
total += amount[i];
}
return total;
}