HOME/Articles/

sum array (snippet)

Article Outline

Python example 'sum array'

Functions in program:

  • def sum_arr(n):

sum array

Python beginners example: sum array

def sum_arr(n):
    res = 0
    for x in n:
        res += x
    return res

nums = [52345,746587,98589,54398,9348,45887,49856]
test = sum_arr(nums)
if test == sum(nums):
    print("Sum of arr: {}".format(test))
else:
    print("Func dosen't work!")
# Most simple algorithm ever! Isn't it!