CS 110X Feb 12 2014 : LAB FOUR
If you can make an LED blink on an Arduino board, you can do anything.
George Heineman
1 There are no easy methods of learning difficult things; the method is to close your door, give out that you are not at home, and work.
1.1 Lab Assignment
In this fourth lab, you are going to get some experience with CSV files and with nested loops. Doing so will prepare you for the HW5 homework assignment to be assigned on Feb 13 2014.
First you must download a Python file lab4.py and store it in a folder on your lab computer.
Then make sure to download the following file and save it to the exact same folder (and keep the name the same); you must do so, otherwise you won’t be able to read this data set for input. In this lab, this file is known as the DataSet.
Write a Python module that allows the user to
print all players whose BA and HR are greater than or equal to n
standard deviation above the respective averages.
The basic idea is to compute two threshold values, one for
home runs totals (HR) and one for batting average (BA).
The threshold is equal to the Average + n*StandardDeviaion
The user is able to enter in the number n which represents how far
above average
1.2 Validation
Once done, your program will look like this:
>>> lab4() Welcome to The Baseball Reporting System There are 1600 records available How many sigmas to use for threshold [1-4]? 2 The following players exceed average + 2 sigma On both HomeRuns and Batting Average Searching for HR >= 32.0638528121 and BA >= 0.327661295493 Miguel Cabrera 44 0.33 Miguel Cabrera 38 0.328 Manny Ramirez 37 0.332 Albert Pujols 37 0.357 Carlos Gonzalez 34 0.336 Ryan Braun 33 0.332 6 players identified
1.3 Structure
I have started you off with a template that contains a number of functions:
countEntries() – Demonstrates how to process a file on disk using a for loop that effecively skips the first (header) line in the file.
lab4 – main function that runs the application
Your task is to complete the remaining functions in the code. Be sure to review the existing functions to see how everything should fit together. Don’t change the functions that should be left alone.
1.4 How To Complete This Lab
You must fill in code in several functions that have already been documented for you:
extractColumn(columnNumber) – Read the DataSet file and create a list of values that just contain the value found in the given column of the underlying DataSet file for each player. Note that the header line in the file is ignored.
In this lab, for example, this function will return a list of 1600 values, one for each player.
computeThreshold(column, numSigma) – Determine and return the threshold (a float) for the values in the designated column in the underlying DataSet.
Threshold is computed as Average + numSigma*StandardDeviation
printPlayers(HR_threshold, BA_threshold) – Print player name and corresponding column values if that player’s HR (total home runs) AND BA (Batting Average) are greater than or equal to the respective threshold values.
When you are done, you will run the lab4() program and demonstrate that you achieved the results as shown earlier.
1.5 Submission Procedure
You must make sure you submit your lab via turnin.
1.6 Version : 2014/02/14
(c) 2014, George Heineman