Question

Case Study Baseball Team Manager For this case study, you’ll use the programming skills that you...

Case Study Baseball Team Manager

For this case study, you’ll use the programming skills that you learn in Murach’s Python Programming to develop a program that helps a person manage a baseball team. This program stores the data for each player on the team, and it also lets the manager set a starting lineup for each game.

After you read chapter 2, you can develop a simple program that calculates the batting average for a player. Then, after you complete most of the other chapters, you can enhance and improve this program.   1

General guidelines

Naming

When creating the folder and file names for your programs, please use the conventions specified by your instructor. Otherwise, for a program that consists of a single file, use this naming convention: first_last_baseball_wkXX.py where first_last specifies your first and last name and wkXX specifies the chapter number, as in wk05. For programs that have multiple files, store the files in a folder named first_last_baseball_wkXX.

When creating names for variables and functions, please use the guidelines and recommendations specified by your instructor. Otherwise, use the guidelines and recommendations specified in Murach’s Python Programming.

User interfaces

You should think of the user interfaces that are shown for the case studies as starting points. If you can improve on them, especially to make them more user-friendly, by all means do so.

Specifications

You should think of the specifications that are given for the case studies as starting points. If you have the time to enhance the programs by improving on the starting specifications, by all means do so.

Use a list to store the players

Update the program so that it allows you to store the players for the starting lineup. This should include the player’s name, position, at bats, and hits. In addition, the program should calculate the player’s batting average from at bats and hits.

What i have so far


def display_menu():
    print("======================================================================")
    print(" Baseball Team Manager")
    print("MENU OPTIONS")
    print("1 - Calculate batting average")
    print("2 - Exit program")
    print("=====================================================================")
  
def convert_bat():
    print("Calculate batting average...")
    num_at_bats = int(input("Enter official number of at bats: "))
    num_hits = int(input("Enter number of hits: "))
    average = num_hits/num_at_bats
    print("Batting average: %.3f" % average)

def main():
    while True:
        display_menu()
        ch = int(input("Menu Option : "))
        if(ch == 1):
            convert_bat()
        elif(ch == 2):
            break
            print("Bye!")
        else:
            print("Not a valid option. Please try again.")
           
  
main()
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the following program to manage the base ball team.

Note: Explanations are provided at the comments in between the code for each function.

Program:

#global declarations

#list of lists which players info, name, position, atbats, hits
players_list=[];
#list that has only selected players
selected_players=[];
#list that has only players name and no other info
players_only=[];

def display_menu():
print("======================================================================")
print(" Baseball Team Manager")
print("MENU OPTIONS")
print("1 - Enter Players details")
print("2 - Calculate batting average")
print("3 - Select players for a Game")
print("4 - Diaplay the selected players")
print("5 - Exit program")
print("=====================================================================")
  
def convert_bat():
print("Calculate batting average for the players list...")
  
#Calculate Batting average for all the players
for single_player in players_list:
print("Batting average for %s is %d" % (single_player[0], single_player[2]/single_player[3]))
  
def player_details():
#get how many playerts needs to be added and their respective information
count = int(input("How many players information needs to be added: "))
while count > 0:
local_list=[]
local_list.append(str(input("Name: ")))
players_only.append(local_list[0])
local_list.append(str(input("position: ")))
local_list.append(int(input("Atbats: ")))
local_list.append(int(input("Hits: ")))
count = count - 1
players_list.append(local_list)

def select_player():
num_players=len(players_only)
print("Total number of players available is %d and select from the list is given below" % num_players)
  
#select the player until we press -1
while True:
for i in players_only:
print(i)
selecting=int(input("Enter the player number or -1 to quit: "))
  
if selecting == -1:
print("selection completed.. Quitting")
break
if players_only[selecting-1] in selected_players:
print("%s Player number already selected" % selecting)
else:
#append the selected_players list with the selected players
selected_players.append(players_only[selecting-1])

def display_selection():
#display the selected players
print("List of selected players:")
for i in selected_players:
print(i)
  
def main():
while True:
display_menu()
ch = int(input("Menu Option : "))
if(ch == 1):
player_details()
elif(ch == 2):
convert_bat()
elif(ch == 3):
select_player()
elif(ch == 4) :
display_selection()
elif(ch == 5):
break
print("Bye!")
else:
print("Not a valid option. Please try again.")

  
main()

Sample Output:

======================================================================
Baseball Team Manager
MENU OPTIONS
1 - Enter Players details
2 - Calculate batting average
3 - Select players for a Game
4 - Diaplay the selected players
5 - Exit program
=====================================================================
Menu Option : 1
How many players information needs to be added: 2
Name: Sachin
position: catcher
Atbats: 10
Hits: 10
Name: Dhoni
position: fielder
Atbats: 10
Hits: 9
======================================================================
Baseball Team Manager
MENU OPTIONS
1 - Enter Players details
2 - Calculate batting average
3 - Select players for a Game
4 - Diaplay the selected players
5 - Exit program
=====================================================================
Menu Option : 2
Calculate batting average for the players list...
Batting average for Sachin is 1
Batting average for Dhoni is 1
======================================================================
Baseball Team Manager
MENU OPTIONS
1 - Enter Players details
2 - Calculate batting average
3 - Select players for a Game
4 - Diaplay the selected players
5 - Exit program
=====================================================================
Menu Option : 3
Total number of players available is 2 and select from the list is given below
Sachin
Dhoni
Enter the player number or -1 to quit: 1
Sachin
Dhoni
Enter the player number or -1 to quit: 1
1 Player number already selected
Sachin
Dhoni
Enter the player number or -1 to quit: 2
Sachin
Dhoni
Enter the player number or -1 to quit: 2
2 Player number already selected
Sachin
Dhoni
Enter the player number or -1 to quit: -1
selection completed.. Quitting
======================================================================
Baseball Team Manager
MENU OPTIONS
1 - Enter Players details
2 - Calculate batting average
3 - Select players for a Game
4 - Diaplay the selected players
5 - Exit program
=====================================================================
Menu Option : 4
List of selected players:
Sachin
Dhoni
======================================================================
Baseball Team Manager
MENU OPTIONS
1 - Enter Players details
2 - Calculate batting average
3 - Select players for a Game
4 - Diaplay the selected players
5 - Exit program
=====================================================================
Menu Option : 5


Add a comment
Know the answer?
Add Answer to:
Case Study Baseball Team Manager For this case study, you’ll use the programming skills that you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question: Case Study Baseball Team Manager For this case study, you’ll use the programming skills that...

    Question: Case Study Baseball Team Manager For this case study, you’ll use the programming skills that you ... Case Study Baseball Team Manager For this case study, you'll use the programming skills that you learn in Murach s Python Programming to develop a program that helps a person manage a baseball team. This program stores the data for each player on the team, and it also lets the manager set a starting lineup for each game After you read chapter...

  • Chapter 05 Case study Baseball team For this case study, you’ll use the programming skills that...

    Chapter 05 Case study Baseball team For this case study, you’ll use the programming skills that you learn in Murach’s Python Programming to develop a program that helps a person manage a baseball team. This program stores the data for each player on the team, and it also lets the manager set a starting lineup for each game. After you read chapter 2, you can develop a simple program that calculates the batting average for a player. Then, after you...

  • Chapter 8 Python Case study Baseball Team Manager For this case study, you’ll use the programming...

    Chapter 8 Python Case study Baseball Team Manager For this case study, you’ll use the programming skills that you learn in Murach’s Python Programming to develop a program that helps a person manage a baseball team. This program stores the data for each player on the team, and it also lets the manager set a starting lineup for each game. After you read chapter 2, you can develop a simple program that calculates the batting average for a player. Then,...

  • Need help writing this code in python. This what I have so far. def display_menu(): print("======================================================================")...

    Need help writing this code in python. This what I have so far. def display_menu(): print("======================================================================") print(" Baseball Team Manager") print("MENU OPTIONS") print("1 - Calculate batting average") print("2 - Exit program") print("=====================================================================")    def convert_bat(): option = int(input("Menu option: ")) while option!=2: if option ==1: print("Calculate batting average...") num_at_bats = int(input("Enter official number of at bats: ")) num_hits = int(input("Enter number of hits: ")) average = num_hits/num_at_bats print("batting average: ", average) elif option !=1 and option !=2: print("Not a valid...

  • Case Study Baseball Team Manager. CMSC 135 Python Chapter 7 Assignment: Use a file to save...

    Case Study Baseball Team Manager. CMSC 135 Python Chapter 7 Assignment: Use a file to save the data Update the program so it reads the player data from a file when the program starts andwrites the player data to a file anytime the data is changed What needs to be updated: Specifications Use a CSV file to store the lineup. Store the functions for writing and reading the file of players in a separate module than the rest of the...

  • Can you please Test and debug the program below using the following specifications? Many thanks! Create...

    Can you please Test and debug the program below using the following specifications? Many thanks! Create a list of valid entries and the correct results for each set of entries. Then, make sure that the results are correct when you test with these entries. Create a list of invalid entries. These should include entries that test the limits of the allowable values. Then, handle the invalid integers (such as negative integers and unreasonably large integers). In addition, make sure the...

  • Help me figure this problem out, please. Use a list to store the players Update the...

    Help me figure this problem out, please. Use a list to store the players Update the program so that it allows you to store the players for the starting lineup. This should include the player’s name, position, at bats, and hits. In addition, the program should calculate the player’s batting average from at bats and hits. Console ================================================================ Baseball Team Manager MENU OPTIONS 1 – Display lineup 2 – Add player 3 – Remove player 4 – Move player 5...

  • 1. You will develop a Python program to manage information about baseball players. The program will...

    1. You will develop a Python program to manage information about baseball players. The program will maintain the following information for each player in the data set: player’s name (string) team identifier (string) games played (integer) at bats (integer) runs scored (integer) hits (integer) doubles (integer) triples (integer) homeruns (integer) batting average (real) slugging percentage (real) The first nine items will be taken from a data file; the last two items will be computed by the program. The following formulas...

  • Week 10 Python programming Baseball Team Manager MENU OPTIONS 1 – Display lineup 2 – Add...

    Week 10 Python programming Baseball Team Manager MENU OPTIONS 1 – Display lineup 2 – Add player 3 – Remove player 4 – Move player 5 – Edit player position 6 – Edit player stats 7 - Exit program POSITIONS C, 1B, 2B, 3B, SS, LF, CF, RF, P Menu option: 1 POS AB H AVG Player 1 Denard Span CF 545 174 0.319 2 Brandon Belt 1B 533 127 0.238 3 Buster Posey C 535 176 0.329 4 Hunter...

  • Write a Python program that stores the data for each player on the team, and it...

    Write a Python program that stores the data for each player on the team, and it also lets the manager set a starting lineup for each game. Questions: - Handle the exception that occurs if the program can’t find the data file. - Handle the exceptions that occur if the user enters a string where an integer is expected. - Handle the exception that occurs if the user enters zero for the number of at bats. - Thoroughly test the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT