We'll be using the SAT data...
Step 1: be able to read the data and select some schools and print the results.
Create the function ExtremeScores(which_column, how_many, is_top), which will print out (not return) the top (or bottom) scores and the schools which have them from the SAT student file. The argument which_column should be the number 3 (for Reading), 4 (Math), 5 (Writing) or 6 (Total, which you'll have to calculate). how_many should be the number of schools, and is_top should be True if you want the highest scores, and False if you want the lowest ones (ignoring schools with "s" as data). For instance, if I wanted the bottom 3 scores in Writing (which_column = 5), then ExtremeScores(5,3,False) would print (I've added commas between the printed columns -- don't worry about doing that if you don't want):
Writing Mean , School 285 , International School of Liberal Arts 291 , HIGH SCHOOL OF WORLD CULTURES 296 , Kingsbridge International High School(Of course, now you can finally find out which school has the highest SAT scores in each of the categories and the total...)
As an aid, here is my answer to this step...
Step 2: Let's let the query page trigger the backend Python program without the Python program needing any user input from the query page.
In other words, just have a button on the query page that causes the backend Python program to produce a fixed response. So create a query web page (called FixedQuery.html) that tells the user that when she presses the sole button, she's get the 5 schools with the lowest total SAT scores (she's be delighted that her school's not there). Transfer the FixedQuery.html page into your public_html directory. Then write the Python program, based on your experience with ExtremeScores() to deliver the answer. Remember:
- the first line (#! /usr/bin/python)
- the Content-type line
- remember to transfer the file using "text" mode in WinSCP if you're working on a Windows system, to translate the "\r\n" line-endings to "\n"
- if you get an INTERNAL SERVER ERROR when you try your program, then try the Python Program Checker.
You may display the result in simple line form (as shown in step 1), or better yet, in table form, like the sample below:
School Total mean SAT score International School of Liberal Arts 5982 (or something)
Step 2: For this step and also for step 3, create a link to both query screens than I can click on in the Comments-to-Teacher.
Step 3: All right, this is the full-service, professional
grade (at a
nominal extra charge) query/answer pair...
Create a new query page (FlexQuery.html) and transfer it to
your public_html
directory. Make the query page allow the user to specify
all the
arguments to ExtremeScores(): which_column, how_many and
is_top,
with appropriate <input> and <select> widgets.
And deliver the
results like this:
The 3 bottom SAT Writing Scores are...
| School | Writing Mean |
| International School of Liberal Arts | 285 |
| HIGH SCHOOL OF WORLD CULTURES | 291 |
| Kingsbridge International High School | 296 |