Question: Let s be a string that contains a sequence of decimal numbers separated by commas, e.g. s = 1.23,2.4,3.123. Write a program that prints the
Let s be a string that contains a sequence of decimal numbers separated by commas, e.g. s = 1.23,2.4,3.123. Write a program that prints the sum of the numbers in the string s. What if the input numbers are separated in the following manner: s = 1.23, 2.4, 3.123 ? Make sure your code generalizes to any string of numbers in this format.

# This is starter code for HW#1 problem #3 myString = '1.23,2.4,3.123' s = myString st_sum = # initialize to empty string my_sum = 0.0 #initialize Sum = 0.0 = for c in s: #iterate over chars in string s # use conditionals to extract numbers in the string print(f'The sum of the numbers in {myString} is {my_sum}')
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
