Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

String processing and manipulation is an important part of scientific computing.

ID: 652764 • Letter: S

Question

String processing and manipulation is an important part of scientific computing. Many data sources store their information in plaintext which can be read in as strings. The data is separated by delimiters, for example a CSV (comma separated values) file may have entries like: where Ago and ID are written into the file as text versions of numbers and the data is separated by commas. Write a program that gets a CSV line from a user (via the command line). Compute the sum of the numbers and display that sum to the command line. find all of the commas and for each of them get a substring us»ng that comma's location substrings o Remember how to get sub-matrices/sub-vectors? You may need to treat the first value (before the first comma) and the last one (after the last comma) "specially". If the substring is a number, add it to your sum Examples

Explanation / Answer

import csv a = 0 b = 0 array = [] read = open("Test.csv", "r") for line in read: array = line.split(",") if array[3] != "program ": #has to match the .csv's first line, 3rd element if array[3] == "Python ": a = a + int(array[2]) if array[3] == "Ruby ": b = b + int(array[2]) print "Sum of Python's numbers: ", a print "Sum of Ruby's numbers: ", b raw_input("Press Enter to Exit") Test.csv name,points,number,program vasko,15,1,Python vlado,12,2,Python tosho,6,6,Ruby test,111,10,Ruby marto,11,4,Python