A project to manage a baseball team's information

(1) Create a program that lets the manager of a baseball team track the data for each player and display the lineup for a baseball game.

(2) Store the data in a text file that is loaded when the program starts.

Sample Console Output

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Baseball Team Management Program
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: 2
Name: Mike
Position: c
At bats: 11
Hits: 4
Mike was added.

Menu option: 1
Player POS AB H AVG
----------------------------------------------------------------
1 Trevor SS 588 173 0.294
2 Garrett 2B 299 74 0.247
3 Tony C 535 176 0.329
4 Hunter RF 580 182 0.314
5 Ian CF 443 113 0.255
6 Nolan 3B 588 185 0.315
7 Daniel 1B 430 129 0.3
8 David LF 374 113 0.302
9 Phillip P 102 12 0.118

Menu option: 3
Enter a lineup number to remove: 10
Mike was deleted.

Menu option: 4
Enter a current lineup number to move: 8
Jarrett was selected.
Enter a new lineup number: 2
Jarrett was moved.

Menu option: 5
Enter a lineup number to edit: 1
You selected Joe POS=2B
Enter a new Position: SS
Joe was updated.

Menu option: 7
Bye!

Specifications

PART 1

Create a program that manages a team by storing data in a list of players. The list will be stored in the main method.

Use a list of lists to store each player in the lineup. The list for a single player includes their name, position, at bats, and hits. Example list with two players:

lineupList = [[Trevor, 'SS', '588', '173'],
[Garrett', '2B', '299', '74']]

For part 1 this list will be declared with a statement in the main method.

Use functions to organize the code making it reusable, easy to read, and easy to maintain. Each of the functions for the six main menu commands should take the list of players as an input parameter.

Use a tuple to store all valid positions (C, 1B, 2B, etc).

When entering/editing positions, the program should always require the user to enter a valid position.

The formula for calculating batting average is:

average = hits / at_bats

The program should round the batting average to a maximum of three decimal places.

If the user enters an invalid menu option, display an error message, and display the menu again so the user can clearly see the valid menu options.

Make sure the user can't enter data that doesnt make sense (such as a negative number of hits or the player having more hits than at bats).

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.

PART 2

Use the BaseballPlayers.csv file that is on the assignment page as the source for the lineup.

Store the functions for writing to and reading from the file of players in a separate module named FileIO.py. Use the csv module for file I/O operations. The function that reads the file will return the list of players. The function that writes to the file will take a lineup list as the input parameter.

For part 2 replace the statement in the main method that declares the lineup list with a statement that calls the read method in the FileIO module. Call the FileIO module in any function that modifies the lineup list.

Handle the exception that occurs if the program can't find the data file. Display a message and continue with the program so that a new file can be created. Do not close the program if no file is found.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.