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)
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:)
Get Answers For Free
Most questions answered within 1 hours.