Programming Assignment #8

Now we can stop arguing...

Due Date : Wednesday, November 8th

 

Introduction

In this week's assignment you will look at two sports themed problems that require conditionals to get the "correct" answers.  You should write these two functions using IDLE and saved in a file called "pa8.py". 

 


Customer Request #1 ( passerRating() - a non-fruitful function )

You are contacted by Jacques Strap, who is the statistician for the football team at Whatsamatta U.  In football there is a statistic for quarterbacks called the "passer rating."  While this only evaluates their abilities in the passing portion of the game (it doesn't take into account their ability to run, their ability to win, their ability to not fumble, etc.) it is often used as one way to compare two quarterbacks to compare their abilities as a passer.

To calculate the passer rating you need five pieces of information:

To calculate the passing rating used in the NFL you:

  1. Calculate four sub stats:
  2. Adjust each of the sub stats:
  3. 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.

FINALLY, in general you can use this number to predict how good of a year the QB was having.  Scores at 85 or worse mean the player was having a BAD year.  Scores above 85 are MEDIOCRE.  Scores above 90 are GOOD, and scores above 95 are GREAT.

Write a function called passerRating() that:

  1. Takes in five parameters representing the five statistics that are listed above:
  2. Calculates the passer rating as described above.
  3. Prints the passer rating, and
  4. Prints the kind of year they are having. 

To give you some numbers to work with, here are some stats through this week of the 2017 NFL football season

Name Attempts Completions Yards TD Interceptions Rating Prediction
Drew Brees

248

175 1951 11 4 101.7 Great
Matt Ryan 232 153 1844 9 6 92.3 Good
Eli Manning 260 167 1600 10 5 86.1 Mediocre
Ben Roethlisberger 275 168 2062 10 9 82.7 Bad
Fake Player 365 312 312 312 51 79.2 Bad

For example:


Customer Request #2 (leadIsSafe() - a fruitful function)

You are contacted by Marge Inovera, who is the statistician for the basketball team at Whatsamatta U.  She notices that the team gets a lead and then starts celebrating too early and then blows the lead in the end (and it is really embarrassing to dump Gatorade on the coach only to later lose the game).

She points you to an article about a statistical technique used to predict if a basketball team holds enough of a lead that they are finally expected to actually win the game.  Basically the technique is as follows:

  1. Take the number of points of the home team
  2. Take the number of points of the away team
  3. Calculate the # of points by which the winning team is ahead
  4. Subtract 3
  5. Add a half-point if the winning team currently has the ball.  Subtract a half-point if the winning team does not have the ball.
  6. If this answer isn't greater than zero than the lead is not safe.
  7. If this answer IS greater than zero than square the answer.  If the result is greater than the number of seconds left in the game than the winning team is expected to be able to win the game.

Write a Python function that:

Using these four pieces of information the program should calculate whether the lead is safe or not and print an appropriate message either way.

 

Please notice that while this isn't too difficult in the end, there are several conditions that need to be considered since you are entering the score based on home/away and the calculation that I describe is based on winning/losing.  Therefore, you need to test with several combinations and make sure that you are representing the correct calculations.

 

Submitting your assignment

As we have done for the last few weeks, you should submit both paper printout for comment and electronic copies for execution:

https://www.cs.uni.edu/~schafer/submit/which_course.cgi