Question: Complete the total_numbers_string() function that takes a single string parameter named numbers_string. The numbers_string consists of several integer values, which may be positive, negative or
Complete the total_numbers_string() function that takes a single string parameter named numbers_string. The numbers_string consists of several integer values, which may be positive, negative or 0, each separated by a comma. For example "1,-50,0,356" would be a valid numbers_string. The function calculates the total of all the integer values in the numbers_string and returns this total. Some examples of the function being called are shown below. Hint: you should use the split() string method.
For example:
| Test | Result |
|---|---|
numbers_string = "-1,5,55,-22,0,31" total = total_numbers_string(numbers_string) print("Total of numbers in string:", total) | Total of numbers in string: 68 |
numbers_string = "101,-24,-510,1025,12" total = total_numbers_string(numbers_string) print("Total of numbers in string:", total) | Total of numbers in string: 604 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
