# Programming Assignment #8

## Now we can stop arguing...

### 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:

• 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:

1. Calculate four sub stats:
• Completion portion (A) = "completions per attempt" times 100 - 30, all divided by 20
• Yards portion (B) = "yards per attempt" - 3, all divided by 4
• Touchdown portion (C) = "touchdowns per attempt" times 20
• Interceptions portion (D) = 2.375 - ("interceptions per attempt" times 25)
2. Adjust each of the sub stats:
• If any of the sub stats (A, B, C, or D) is above 2.375 you should set it to 2.375
• If any of the sub stats is below 0 you should set it to 0
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:

• takes in four parameters:
• home team's score (an integer)
• away team's score  (an integer)
• if the home team has the ball (a boolean value)  (NOTE: this is slightly different than what is mentioned above)
• the number of seconds left in the game (an integer)
• returns a boolean value indicating if the WINNING team's lead is safe.

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.