Question

In: Computer Science

PYTHON (BEGINNER) program that allows the user to choose any of the three sports options described...

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.

Solutions

Expert Solution

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")



Related Solutions

write a complete C++ program that allows the user to choose from one of several options....
write a complete C++ program that allows the user to choose from one of several options. The program will display a menu and each option will be in a separate function. The program will continue looping until the user chooses to quit. The module descriptions are given below. a. Prompt for and take as input 3 floating point values (l, w, and h). The program will then calculate the volume (volume = l*h*w ). The program should then output to...
Create a Python program that: Allows the user to enter a phrase or sentence. The program...
Create a Python program that: Allows the user to enter a phrase or sentence. The program should then take the phrase or sentence entered Separate out the individual words entered Each individual word should then be added to a list After all of the words have been place in a list Sort the contents of the list Display the contents of the sorted list with each individual word displayed on a separate line Display a message to the user indicating...
PYTHON BEGINNER Problem Create a program that lets the user play a simplified game of Blackjack,...
PYTHON BEGINNER Problem Create a program that lets the user play a simplified game of Blackjack, which is played between the user and an automated dealer as follows. The dealer shuffles a standard deck of 52 cards, draws two cards, and gives them to the user. The user can then choose to request another card from the dealer, adding it to their hand. The user can continue to request cards or choose to stop at any time. After each time...
How to do this in Python (using Lists): Create a python program that allows a user...
How to do this in Python (using Lists): Create a python program that allows a user to display, sort and update as needed a List of U.S States containing the State Capital and State Bird. You will need to embed the State data into your Python code. The user interface will allow the user to perform the following functions: 1. Display all U.S. States in Alphabetical order along with Capital and Bird 2. Search for a specific state and display...
Use Visual Python or equivalent, to write a program that allows the user to observe the...
Use Visual Python or equivalent, to write a program that allows the user to observe the following: Damped and forced harmonic oscillators. The program should be user friendly and have default values for the initial velocities, positions, masses, and spring constants as well as damping constants. Values and frequencies for the forced oscillators should also be given. It should allow the user to input values for the velocities, positions, spring constants, and masses. The program should determine automatically the scale...
9) This is in Python Code a program that allows the user to manage its expenses...
9) This is in Python Code a program that allows the user to manage its expenses accepting the following commands: - Add <player_name> -> This command adds a new player to the system. Assume there can’t be repeated names. If a name already exists then an error is shown to the user. - Score <player_name> <score> -> This command adds the score to the player with the name player-name. Each score needs to be added individually - Report -> This...
Write in Python and as 2 seperate programs Write a program that allows the user to...
Write in Python and as 2 seperate programs Write a program that allows the user to enter the total rainfall for each of 12 months into a LIST. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest rainfall amounts. Data: January 7.9 inches February 10.1 inches March 3.4 inches April 6.7 inches May 8.9 inches June 9.4 inches July 5.9 inches August 4.1 inches September...
Python Add a command to this chapter’s case study program that allows the user to view...
Python Add a command to this chapter’s case study program that allows the user to view the contents of a file in the current working directory. When the command is selected, the program should display a list of filenames and a prompt for the name of the file to be viewed. Be sure to include error recovery in the program. If the user enters a filename that does not exist they should be prompted to enter a filename that does...
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT