-
-
Save Sandy4321/6272dc4a6e7dd3ab6323 to your computer and use it in GitHub Desktop.
Calculates the Passer Rating (passer efficiency or pass efficiency) of a player given some variables. Use at own risk, old-as-fuck code here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This Python application will calculate the passer rating | |
# (passer efficiency or pass efficiency) given the five required variables. | |
# | |
# Variables to be used as values are defined below. Set to strings so input | |
# can be anything. Later the strings will be converted to numbers, given | |
# they pass a series of error checking tests. | |
COMP = "null" | |
ATT = "null" | |
YARDS = "null" | |
TD = "null" | |
INT = "null" | |
# Function defined to check if string is a valid number, | |
# and if it is larger than zero. (Invalid if < 0 | |
def checkIfNum(stringToTest): | |
try: | |
temp = float(stringToTest) | |
except ValueError: | |
# isn't a number | |
return False | |
else: | |
if(temp < 0): | |
return False | |
else: | |
# is a number | |
return True | |
# Get user input of the numbers, and check to make sure that the input | |
# is a valid number. If it's not a valid number, it will re-ask for input. | |
while checkIfNum(COMP) == False: | |
COMP=raw_input('Enter the number of completions:') | |
while checkIfNum(ATT) == False: | |
ATT=raw_input('Enter the number of attempts:') | |
while checkIfNum(YARDS) == False: | |
YARDS=raw_input('Enter the total number of yards:') | |
while checkIfNum(TD) == False: | |
TD=raw_input('Enter the number of touchdown passes:') | |
while checkIfNum(INT) == False: | |
INT=raw_input("Enter the number of interceptions:") | |
# Converts all the strings to integers (already verified as valid numbers). | |
COMP=int(COMP) | |
ATT=int(ATT) | |
YARDS=int(YARDS) | |
TD=int(TD) | |
# INT is the name of the variable which holds the number | |
# of INTerceptions, int is the built in function which | |
# converts the strings to integers. | |
INT=int(INT) | |
# The calculations are processed here using the newly converted integers. | |
# The resulting calculations are easy to determine from the variable names. | |
completionPercentage = ((COMP/ATT*100)-30)*.05 | |
print("Completion Percentage = %d") % (completionPercentage) | |
avgYardPerAttempt = ((YARDS/ATT)-3)*0.25 | |
print("Average Yards Per Attempt = %d") % (avgYardPerAttempt) | |
percentOfTdPasses = (TD/ATT)*20 | |
print("Percentage of Touchdown Passes = %d") % (percentOfTdPasses) | |
percentOfInt = 2.375 - (INT/ATT * 25) | |
print("Percentage of Interceptions = %d") % (percentOfInt) | |
passerRating = ((completionPercentage + avgYardPerAttempt | |
+ percentOfTdPasses + percentOfInt)/6)*100 | |
# After the final Passer Rating has been calculated, | |
# the result is printed on screen. | |
print("Passer Rating = %d") % (passerRating) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment