← Back to challenges

Adding Numbers in a String

PythonMediumlanguage_fundamentalsnumbers

Instructions

Given a string of numbers separated by a comma and space, return the total sum of all the numbers.

Examples

add_nums("2, 5, 1, 8, 4") ➞ 20

add_nums("1, 2, 3, 4, 5, 6, 7") ➞ 28

add_nums("10") ➞ 10

Notes

  • Numbers will always be separated by a comma and space.
  • Your function should accept negative numbers.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Length and Element of Range