In: Computer Science
PYTHON (BEGINNER) program that allows the user to choose any of the three sports options described below and computes the relevant statistic in each case: Quidditch Score Total: Determined based on the number of goals and whether or not the snitch was caught. A goal is scored by propelling the quaffle through a hoop and each earns the team 10 points. If a team catches the snitch, that team earns an additional 30 points. The snitch can be caught at most once. More details on Quidditch available from the International Quidditch Association. (Simplified) Quarterback Rating: Defined as 100 * [5(completions/attempts – 0.3) + 0.25(passing_yards/attempts-3) + 20(touchdown_passes/attempts) + 2.375 – (25 * interceptions/attempts)]/6, where attempts is the number of passing attempts made, completions is the number of completed passing attempts, touchdown_passes is the number of passes for a touchdown, and interceptions is the number of times the ball was intercepted. A perfect passer rating in the NFL is considered to be a 158.3. In addition to the rating, tell the user whether or not the quarterback is a perfect passer. Gymnast Score: Begins with six scores, one for difficulty and five for execution, each between 0 and 10. Of the execution scores, the highest and lowest are dropped. The final score is given by the sum of the difficulty score and the average of the three remaining execution scores. Input Validation: Check if you are going to divide by zero when relevant, and do not do the calculation if that is the case. Before typecasting user inputs to an int, check that it is only digits, and don’t typecast or do the calculation otherwise. (For this assignment, do not worry about checking if floats are valid.) In any case where an error is detected, output an error message. Do not continue the calculation. You may additionally output a result of zero in such a case.
1). ANSWER :
GIVENTHAT :
import sys
def Quidditch(goal1,goal2,snitch):
score1 = goal1*10;
score2 = goal2*10;
if(snitch==1):
score1+=30
elif(snitch==2):
score2+=30
print("Team 1 scored : "+str(score1)+"\n")
print("Team 2 scored : "+str(score2))
if score1>score2:
print("\nTeam 1 won!")
elif score2>score1:
print("\nTeam 2 won!")
else:
print("\nIt's a tie!")
def Quarterback(comp,pass_yard,attempt,touchdown,inter):
score = ((5*((comp/attempt)-0.3)) + (0.25*((pass_yard/attempt)-3)) + 20*(touchdown/attempt) + 2.375 - (25*(inter/attempt)))*100/6
if score > 158.3:
print("The player is a perfect passer\n")
print("The player's rating is "+str(score))
def Gymnast(score,execute):
mx = max(execute)
mn = min(execute)
rate = score + (sum(execute)-mx-mn)/3
print("The gymnast scored "+str(rate)+" points")
n = input("Enter 1 for Quidditch, 2 for Quarterback, 3 for Gymnastics : ")
if n.isdigit() and int(n)<=3 and int(n)>=1 :
n = int(n)
else:
print("Invalid input")
sys.exit()
if n==1:
goal1=input("Enter goals scored by Team 1 : ")
if goal1.isdigit() and int(goal1)>=0:
goal1 = int(goal1)
else:
print("Invalid input")
sys.exit()
goal2=input("Enter goals scored by Team 2 : ")
if goal2.isdigit() and int(goal2)>=0:
goal2 = int(goal2)
else:
print("Invalid input")
sys.exit()
snitch = input("Enter 1 if Team 1 caught the snitch, 2 if Team 2, 0 if neither : ")
if snitch.isdigit() and int(snitch)<=2 and int(snitch)>=0 :
snitch = int(snitch)
else:
print("Invalid input")
sys.exit()
Quidditch(goal1,goal2,snitch)
elif n==2:
completion = input("Enter completions : ")
if completion.isdigit() and int(completion)>=0:
completion = int(completion)
else:
print("Invalid input")
sys.exit()
pass_yard = input("Enter passing yards : ")
if pass_yard.isdigit() and int(pass_yard)>=0:
pass_yard = int(pass_yard)
else:
print("Invalid input")
sys.exit()
attempt = input("Enter attempts : ")
if attempt.isdigit() and int(attempt)>=0:
attempt = int(attempt)
else:
print("Invalid input")
sys.exit()
if(attempt==0):
print("Divide by zero exception")
sys.exit()
touchdown = input("Enter touchdown passes : ")
if touchdown.isdigit() and int(touchdown)>=0:
touchdown = int(touchdown)
else:
print("Invalid input")
sys.exit()
inter = input("Enter interceptions : ")
if inter.isdigit() and int(inter)>=0:
inter = int(inter)
else:
print("Invalid input")
sys.exit()
Quarterback(completion,pass_yard,attempt,touchdown,inter)
elif(n==3):
score = input("Enter difficulty score : ")
if score.isdigit() and int(score)>=0:
score = int(score)
else:
print("Invalid input")
sys.exit()
execute = []
for i in range(5):
temp = input("Enter execution score " + str(i+1)+ " : ")
if temp.isdigit() and int(temp)>=0:
execute.append(int(temp))
else:
print("Invalid input")
sys.exit()
Gymnast(score,execute)
else:
print("Invalid input")