Given an array of integers, find the sum of its elements.
For example, if the array ,ar[1, 2, 3] ,(1+2+3) so return = 6
here`s is my sample code
Complete the 'simpleArraySum' function below.
The function is expected to return an INTEGER.
The function accepts INTEGER_ARRAY ar as parameter.
import math
import os
import random
import re
import sys
def simpleArraySum(ar):
# Write your code here
x=0
for i in range(0,ar_count):
x += ar[i]
return x
if name == 'main':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
ar_count = int(input().strip())
ar = list(map(int, input().rstrip().split()))
result = simpleArraySum(ar)
fptr.write(str(result) + '\n')
fptr.close()
Top comments (0)