Back to Freecodecamp

Challenge 211: Array Sum

curriculum/challenges/english/blocks/daily-coding-challenges-python/6994cff2290543b3aec9f510.md

latest1.1 KB
Original Source

--description--

Given an array of numbers, return the sum of all the numbers.

--hints--

sum_array([1, 2, 3, 4, 5]) should return 15.

js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sum_array([1, 2, 3, 4, 5]), 15)`)
}})

sum_array([42]) should return 42.

js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sum_array([42]), 42)`)
}})

sum_array([5, -2, 7, -3]) should return 7.

js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sum_array([5, -2, 7, -3]), 7)`)
}})

sum_array([203, 145, -129, 6293, 523, -919, 845, 2434]) should return 9395.

js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sum_array([203, 145, -129, 6293, 523, -919, 845, 2434]), 9395)`)
}})

sum_array([0, 0]) should return 0.

js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sum_array([0, 0]), 0)`)
}})

--seed--

--seed-contents--

py
def sum_array(numbers):

    return numbers

--solutions--

py
def sum_array(numbers):

    return sum(numbers)