Activity : Who should I pick for my team?
Introduction
I bet that at least some of you play Fantasty Football or follow your favorite team. Have you ever gotten in to an argument about who is the better quarterback - Tom Brady or Ben Rothlisberger? [Well, this year that's a no brainer - it's Tom Brady. But, still, Go Steelers!]
One of the ways we could answer this question without just personal opinion is through the use of the Quarterback Passer Rating. The QB Passer Rating is a standard statistic in football that can be used to compare two QBs. To calculate the passer rating you need five pieces of information:
- the number of passes attempted
- the number of passes completed
- total passing yards
- the number of touchdowns thrown
- the number of interceptions thrown
To calculate the passing rating used in the NFL you:
- Calculate four sub stats:
- Completion portion (A)
- You calculate "completions per attempt" and then times 100 - 30, all divided by 20
- Yards portion (B)
- You calculate "yards per attempt" - 3, all divided by 4
- Touchdown portion (C)
- You calculate "touchdowns per attempt" times 20
- Interceptions portion (D)
- You calculate "interceptions per attempt" multiply this by 25 and then SUBTRACT FROM 2.375
- That is, 2.375 - (IPA*25)
- Completion portion (A)
- Adjust each of the sub stats:
- If any of the sub stats (A, B, C, or D) is above 2.375 you should set those stats to equal 2.375
- If any of the sub stats is below 0 you should set those stats to equal 0
- Calculate the passing rating by taking the sum of all four adjusted values, dividing by 6, then multiplying by 100
This final result is their passer rating.
[Note, that can be a little bit confusing to read in text. You can look up "Passer Rating" on wikipedia. They structure their formulas a bit differently but it is the same result.]
FINALLY, in general you can use this number to predict how good of a year the QB is having (or had).
Score | Rating |
---|---|
85 or lower | Bad |
Above 85 but 90 or lower | Mediocre |
Above 90 but 95 or lower | Good |
Above 95 | Great |
For this assignment we will use these files of data from the 2020 season:
Program Guide
For this assignment you should create the following functions in a file called quarterbacks.py
In this assignment you will make three functions. The first two are smaller, helper functions that will be used by the third function.
Create a function called: passerRating()
This function should:
- Parameters - the five parameters listed prevously IN THIS ORDER
- the number of passes attempted
- the number of passes completed
- total passing yards
- the number of touchdowns thrown
- the number of interceptions thrown
- Actions:
- Using the formula listed above calculate the passer rating
- Returns:
- The passer rating as a floating point number rounded to two decimal places
- Example Run
- Ben Rothlisburger's stats for 2017 were:
- Ben Rothlisburger's stats for 2017 were:
Create a function called: ratingCategory()
This function should:
- Parameters -
- a single QB passer rating
- Actions:
- Using the categories listed above caculates and returnsthe string containing the kind of year they are having.
- Returns:
- The String of the kind of year they are having
- Example Run
- Ben Rothlisburger's stats for 2017 were:
- Ben Rothlisburger's stats for 2017 were:
Create a function called: addColumns()
This function should:
- Take two parameters:
- input file name
- output file name
- Returns:
- Nothing
- Actions:
- Opens the input file
- Opens the output file
- Pulls off the header and adds two more columns labeled "PasserRating" and "Classification"
- For each player provided in the data file you opened:
- extract the appropriate columns
- use the two helper functions you just created to calculate passer rating and classification
- writes the original data PLUS the passer rating and the classification to the output file
- Closes both files
- Example Output
Testing Your Code
- Go to the AutoLab Homepage for the course
- https://hypnos.cs.uni.edu/courses/CSED1320-F21/assessments
- Log in if necessary
- For each of the assignments listed above, find their submission link under the "Practice" heading
- Upload the corresponding python file for that assignment.
- When the "handin history" page comes up you will need to refresh the page until a score of either 0 or 1 is shown with your assignment.
- Click on the 0/1 score to get feedback.
- Read the information carefully if you received a score of 0 and figure out what you need to do to fix the problem.
- Ask for help from me or other students if you don't understand an error message.
- Resubmit until the program earns a 1.