Page 1 of 1

3. Cleaning Data: Let s be a string that contains a sequence of decimal numbers separated by commas, but somehow the dat

Posted: Sat Feb 19, 2022 3:21 pm
by answerhappygod
3 Cleaning Data Let S Be A String That Contains A Sequence Of Decimal Numbers Separated By Commas But Somehow The Dat 1
3 Cleaning Data Let S Be A String That Contains A Sequence Of Decimal Numbers Separated By Commas But Somehow The Dat 1 (84.98 KiB) Viewed 67 times
***USE STARTER CODE PLEASE***
3. Cleaning Data: Let s be a string that contains a sequence of decimal numbers separated by commas, but somehow the data is corrupted and a random * shows up either right after a comma, before a comma, or before the first term of an integer number. e.g. (that's exempli gratia, latin abbreviation of 'for example’) s = ‘1.23,*2.4*, 3.123,*5.1, 8.7*, *7.23, *3.23*". Write a program that prints the sum of the numbers in the string s. Note, the whitespace is unevenly distributed in the string as well. Do this 2 ways: 1. without using any built in functions or methods associated to the string object but with a for or while loop, and 2. with built in string methods.
=# # # method 1 # # # cleaning data example # # ??? indicates you will need to fill in myStr = '1.23, *2.4*, 3.123, *5.1, 8.7*, *7.23, *3.23*' # subStr = = 0 tally for s in myStr: if s == ',': print(subStr) tally += float(subStr) subStr = elif s == '*'; pass elif ??? ??? else: ??? print(subStr) tally += float(subStr) print(tally) =# = # # # method 2 myStr2 = myStr.replace('*','') print(myStr2) sSplit myStr2.split(',') rint(sSplit) # # you can now use other string methods to finish this up