Question

Console ================================================================                        Baseball Team Manager MENU OPTIONS 1 – Display

Console

================================================================

                       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

Team data file could not be found.

You can create a new one if you want.

================================================================

Menu option: 2

Name: Mike

Position: SS

At bats: 0

Hits: 0

Mike was added.

Menu option: X

Not a valid option. Please try again.

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

Menu option: 7

Bye!

Specifications

· 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.

Use import csv to store a lineup on Excel (this does not need to be a completed excel file since the file will be created by the Add player option manually).

The line up is shown in the menu option 1 and those are the entries as shown above for the Baseball Team Manager instructions.

Thank you for your help!!!(any comments on how to use the CSV will also be greatly appreciated)

Homework Answers

Answer #1

Hello, Student I hope you are doing great in lockdown.

Here is code for the Baseball Team Manager, still if you have any doubt then feel free to ask in comment section, I am always happy to help you.

Please upvote.

baseball.py


#Pre-defined Players
players = [["Joe", "P", 10, 2], ["Tom", "SS", 11, 4], ["Ben", "3B", 0,0]]
positions = ("1B", "2B", "3B", "C", "LF", "SS", "CF", "RF", "P")


#Function to Print list of Players
def list_All_Players():
             print("#\t" + "Name\t" + "Pos\t" + "Bat\t" + "Hit")
             print("------------------------------------------------------------------")
             for player in players:
                          print(str(players.index(player)) + "\t" + player[0]\
                                + "\t" + player[1] + "\t" + str(player[2]) +\
                                "\t" + str(player[3]))

#Menu 
def show_Menue():
             print("\t\t Baseball Team Manager")
             print("-------------------------------------------------------------------")
             print("Menu Options")
             print("1-Display the lineup")
             print("2-Add Player")
             print("3-Remove Player")
             print("4-Move Player")
             print("5-Edit Player Position")
             print("6-Edit Player Stats")
             print("7-Exit Program")
             print("Positions")
             print("C, 1B, 2B, 3B, SS, LF, RF, P")
             print("-------------------------------------------------------------------")
             print("-------------------------------------------------------------------")


#Function to edit player Positions
def edit_Player_Position():
             playerno = int(input("Enter a player # \t"))
             newposition = input("Enter a new position \t")
             while newposition not in positions:
                          newposition = input("Enter a valid position \t")
             players[playerno][1] =  newposition    
#Moving a player                                          
def move_A_Player():
             playerno = int(input("Enter a player # \t"))
             newnum = int(input("Enter a number to move player to \t"))
             moved = players.pop(playerno)
             players.insert(newnum, moved)
#Removing a player             
def remove_A_Player():
             playerno = int(input("Enter a player # you want to remove \t"))
             players.remove(players[playerno])
#Add new Player
            
def add_New_Player():
             name = str(input("Name: "))            
             position = str(input("Postion: "))            
             atbats = int(input("At Bats: "))             
             hits = int(input("Hits: "))
             player = []
             player.append(name)
             player.append(position)
             player.append(atbats)
             player.append(hits)
             players.append(player)

#Editing Player stats
             
def edit_Player_Stats():
             playerno = int(input("Enter a player # \t"))
             if choice == 1:
                          atbat = int(input("Enter new at bat value \t"))
                          players[playerno][2] =  atbat
             elif choice ==2:
                          hits = int(input("Enter a new hit value \t"))
                          players[playerno][3] =  hits                         
show_Menue() #Menu Call
option  = int(input("Please enter your option \t"))
while option != 7:
             if (option == 1):
                          list_All_Players()
             elif (option ==2):
                          add_New_Player()
             elif (option == 3):
                          remove_A_Player()
             elif (option == 4):
                          move_A_Player()
             elif (option == 5):
                          edit_Player_Position()
             elif (option ==6):
                          edit_Player_Stats()
             if (option ==7):
                           print("Bye") 
             option = int(input("Please enter your option\t"))
                          
                          
             




Output: - Refer to screenshots

How to use the CSV :-

You can use csv library to implement this with a csv to store or read from that file.

import csv and then open that that file using syntax (you can read and implement from internet)

and you can store all the data into csv file,and at a same time you can read from it.

Feel free to ask in comment section (if needed).

Please do not forget to hit that like or thumbs-up button, it really motivates me<3

Thank you!!

Have a nice day:)

Know the answer?
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
Similar Questions
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2....
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2. Calculate Current in Amps 3. Calculate Voltage in volts 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for voltage in Volts and the current in Amps. Use the following formula: R= E/i Where: E= voltage in volts I= current in amps R= resistance in ohms If the user enters 2 the program should ask for the voltage...
This program will store roster and rating information for a soccer team. Coaches rate players during...
This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team. (1) Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jersey numbers in one int vector and the ratings in another int vector. Output these vectors (i.e., output the roster). (3 pts) Ex: Enter player 1's jersey number: 84 Enter player 1's...
5.27 LAB*: Program: Soccer team roster (Vectors) This program will store roster and rating information for...
5.27 LAB*: Program: Soccer team roster (Vectors) This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team. (1) Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jersey numbers in one int vector and the ratings in another int vector. Output these vectors (i.e., output the roster). (3 pts) Ex: Enter player...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts,...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts, it will present a welcome screen. You will ask the user for their first name and what class they are using the program for (remember that this is a string that has spaces in it), then you will print the following message: NAME, welcome to your Magic Number program. I hope it helps you with your CSCI 1410 class! Note that "NAME" and "CSCI...
IN PYTHON Menu: 1. Hotdog. ($2) 2. Salad ($3)  3. Pizza ($2) 4.Burger ($4) 5.Pasta ($7) Write...
IN PYTHON Menu: 1. Hotdog. ($2) 2. Salad ($3)  3. Pizza ($2) 4.Burger ($4) 5.Pasta ($7) Write a menu-driven program for  Food Court. (You need to use functions!) Display the food menu to a user . 5 options Use numbers for the options and for example "6" to exit. Ask the user what he/she wants and how many of it. (Check the user inputs) AND use strip() function to strip your inputs(if needed) Keep asking the user until he/she chooses the exit...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT