SAT homework

NOTE: You MAY NOT use a spreadsheet to look at or process the data file below.  That's because some of this is easy to do using a spreadsheet for small and medium sized data, but once you get to very large quantities of data, spreadsheets lose their appeal.  Also, you can't easily process data automatically for others in real time using a spreadsheet (at least not without a good deadl of effort).

Here is the full file of 2010 SAT scores for NYC schools: SAT-2010.csv

Create the following 2 functions, upload your .py file containing them and also put some results (detailed below) from those functions into the Comments-to-Teacher...


1. Create the function highlow(filename) that will read the CSV file whose filename is provided, calculate the sum of the 3 different SAT scrores for each school, and return a string that can be printed out.  The string answer should look like the following (but with real top and bottom school names and scores):

'Potter Corner school is highest with a score of 2212\nVoldy Academy is lowest with a score of 1501'

Put that result string into the Comments-to-Teacher


 2. This is an exercise in creating lists of lists and using the sorted() function.

Create the function nthSchool(filename,whichscore,nth) which will be given the filename, a string and a number.  Its job is to return a little list containing the chosen score and the school name for the school with the nth highest score.

Details: the argument whichscore must be one of the following 3 string possibilities: "reading" or "writing" or "math".  And this will choose which of the 3 scores that every school has available to use.

Details: the nth argument can be positive or negative or zero.  0 means highest score, 1 means the second highest score, -1 means the lowest score, -2 means the second lowest score.  This numbering is easy to use once you have a list in decreasing order of score (highest to lowest).

Return value:  The return value of the function should be a list of two elements: the requested score and the school name.  Example:

>>> print(nthSchool("SAT-2010.csv","reading",99))   # the 100th highest reading score...
[419, 'Bronx High School for the Visual Arts ']

>>>print(nthSchool("SAT-2010.csv","math",-2))  # not the lowest, but the second lowest math score
[306, 'EVANDER CHILDS HIGH SCHOOL ']

If I wanted the school with the 14th highest writing score, I would call nthSchool("SAT-2010.csv","writing",13).  Notice that I put 13 as the argument and not 14 -- that's because numbering starts at 0, meaning that if I wanted the school with the highest math score, I would call: nthSchool("SAT-2010.csv","math",0). Also, negative numbering should also be possible with your function, so if I wanted the school with the lowest reading score, I'd ask for nthSchool("SAT-2010.csv","reading",-1).

Finally, put into the Comments-toTeacher the return value of:
 nthSchool("SAT-2010.csv","writing",11)