Question

In: Computer Science

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

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

Menu option: 1

Player POS AB H AVG

----------------------------------------------------------------

1 Denard OF 545 174 0.319

2 Joe 2B 475 138 0.291

3 Buster C 535 176 0.329

4 Hunter OF 485 174 0.359

5 Brandon SS 532 125 0.235

6 Eduardo 3B 477 122 0.256

7 Brandon 1B 533 127 0.238

8 Jarrett OF 215 58 0.27

9 Madison SP 103 21 0.204

Menu option: 7

Bye!

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

· Make sure that the user’s data entries are valid.

Edit this code and any comments you could put in the CSV parts to help explain how they work or what they do would be a great help!

players = [["Joe", "2B", 10, 2], ["Tom", "SS", 11, 4], ["Ben", "3B", 0,0]]
pos=('C', '1B', '2B', '3B', 'SS', 'LF', 'CF', 'RF', 'P')

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]))
def show_Menue():
print("====================================================================")
print("\t\t\t Baseball Team Manager")
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(pos)
print("====================================================================")
def edit_Player_Position():
playerno = int(input("Enter a player number \t"))
newposition = input("Enter a new position \t")
while newposition not in pos:
newposition = input("Enter a valid position \t")
players[playerno][1] = newposition
def move_A_Player():
playerno = int(input("Enter a player number \t"))
newnum = int(input("Enter a number to move player to \t"))
moved = players.pop(playerno)
players.insert(newnum, moved)

def remove_A_Player():
playerno = int(input("Enter a player number you want to remove \t"))
players.remove(players[playerno])
  
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)

def edit_Player_Stats():
playerno = int(input("Enter a player number \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()
option = int(input("Menu 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("Menu option\t"))

Solutions

Expert Solution

#main.py

import file as f #importing file which contains read and write functions of csv file
pos=('C', '1B', '2B', '3B', 'SS', 'LF', 'CF', 'RF', 'P') #positions

def list_All_Players(): #to display the players list
players=f.read() #read playes from csv file
print(" \t" + "Name\t" + "Pos\t" + "Bat\t" + "Hit\t"+"Avg")
print("------------------------------------------------------------------")
i=1
for player in players:
avg=round((int(player[3]))/int(player[2]),3) #calculating average
print(str(i)+"\t"+player[0]+"\t"+player[1]+"\t"+str(player[2])+"\t"+str(player[3])+"\t"+str(avg))
i+=1
def show_Menue(): #menu
print("====================================================================")
print("\t\t\t Baseball Team Manager")
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(pos)
print("====================================================================")
def edit_Player_Position(): #edit player position
list=f.read()
playerno = int(input("Enter a player number \t")) #read player number to edit
newposition = input("Enter a new position \t") #read new position
while newposition not in pos: #read position until valid
newposition = input("Enter a valid position \t")
list[playerno-1][1] = newposition #change the position
f.write(list) #update the file
def move_A_Player():
list=f.read()
playerno = int(input("Enter a player number \t"))   #read player number to move
newnum = int(input("Enter a number to move player to \t")) #read moving position
moved = list.pop(playerno-1)
list.insert(newnum-1, moved)
f.write(list) #update the file

def remove_A_Player():
list=f.read()
playerno = int(input("Enter a player number you want to remove \t")) #read player number to remove
del list[playerno-1] #delete the player
f.write(list) #update the file
  
def add_New_Player():
players=f.read()
name = str(input("Name: "))
position = str(input("Postion: "))
while position not in pos:
position = input("Enter a valid position \t")
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)
f.write(players) #update the file

def edit_Player_Stats():
players=f.read()
playerno = int(input("Enter a player number \t"))
choice=int(input("Enter choice"))
if choice == 1:
atbat = int(input("Enter new at bat value \t"))
players[playerno-1][2] = atbat
elif choice ==2:
hits = int(input("Enter a new hit value \t"))
players[playerno-1][3] = hits
f.write(players) #update the file
show_Menue()
option = int(input("Menu 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()
option = int(input("Menu option\t"))
if (option ==7):
print("Bye")

#file.py   

## Function to read data from players.csv file
def read():
list=[]
try:
file=open("players.csv","r") #open file
lines=file.readlines() #read the file
for line in lines:
line=line.strip() #remove extra spaces
l=line.split(",")
list.append(l) #append to list
return list
except FileNotFoundError: #raise filenotfound exception
print("File not found")   
  
## Function that writes data to the players.csv file from the list
def write(list):
try:
file=open("players.csv", "w") #open file
for line in list:
file.writelines(line[0]+","+line[1]+","+str(line[2])+","+str(line[3])+"\n") #write to file
except FileNotFoundError:
print("File not found")

#players.csv example file

Dominick,1B,545,174
supriya,C,523,152
Jack,RF,396,125
Alberto,3B,72,19

output:


Related Solutions

                      Contact Manager COMMAND MENU ---------------------------------------------------------- list - Display all contacts view - View
                      Contact Manager COMMAND MENU ---------------------------------------------------------- list - Display all contacts view - View a contact add - Add a contact del - Delete a contact exit - Exit program Command: list 1. Tom van Rossum 2. Edward Idle Command: view Number: 2 Name: Edward Idle Email: [email protected] Phone: +44 20 7946 0958 Command: add Name: John Smith Email: [email protected] Phone: 559-123-4567 John Smith was added. Command: list 1. Tom van Rossum 2. Edward Idle 3. John Smith Command: exit...
The program is to be called CarClub The application will display menu as below 1. load...
The program is to be called CarClub The application will display menu as below 1. load cars 2. display all cars 3. search car 4 count cars older the 30 years 5 exit Please enter your option: Load car menu should read input data from text file name (car.txt) Car class have 4 data members which are. Car make, car model, car year and car price In addition If both car year and price were not provided, year has a...
Create a menu in Java. A menu is a presentation of options for you to select....
Create a menu in Java. A menu is a presentation of options for you to select. You can do this in the main() method. 1. Create a String variable named menuChoice. 2. Display 3 options for your program. I recommend using 3 System.out.println statements and a 4th System.out.print to show "Enter your Selection:". This needs to be inside the do -- while loop. A. Buy Stock. B. Sell Stock X. Exit Enter your Selection: 3. Prompt for the value menuChoice....
Class, Let's create a menu in Java. A menu is a presentation of options for you...
Class, Let's create a menu in Java. A menu is a presentation of options for you to select. You can do this in the main() method. 1. Create a String variable named menuChoice. 2. Display 3 options for your program. I recommend using 3 System.out.println statements and a 4th System.out.print to show "Enter your Selection:". This needs to be inside the do -- while loop. A. Deposit Cash. B. Withdraw Cash X. Exit Enter your Selection: 3. Prompt for the...
Java code for a binary tree that does the following:  Display a menu to the...
Java code for a binary tree that does the following:  Display a menu to the user and request for the desired option.  Based on the user’s input, request for additional information as follows: o If the user wants to add a node, request for the name (or ID) of the new node to be added as well as the name of the desired parent of that node.  If the parent node already has two children, the new...
Java code for a binary tree that does the following:  Display a menu to the...
Java code for a binary tree that does the following:  Display a menu to the user and request for the desired option.  Based on the user’s input, request for additional information as follows: o If the user wants to add a node, request for the name (or ID) of the new node to be added as well as the name of the desired parent of that node.  If the parent node already has two children, the new...
A baseball analyst is trying to predict the number of wins of a baseball team by...
A baseball analyst is trying to predict the number of wins of a baseball team by using the team’s earned run average (ERA). He used data from 12 major league baseball teams and developed the following regression model and ANOVA table. Use Alpha = 0.05Perform a t-test to determine if there is a linear relationship between the number of wins and ERA. The regression equation is y=3+1.5x. and Sb1 = .22 Source                      df                            SS                     MS                 F Regression                1                              1346                1346              31.01 Error                        10                               434                  ...
Use C++ to create an application that provide the menu with two options TemperatureConverter_Smith.cpp MENU CONVERTER...
Use C++ to create an application that provide the menu with two options TemperatureConverter_Smith.cpp MENU CONVERTER TEMPERATURE – JAMES SMITH Convert Fahrenheit temperature to Celsius Convert Celsius temperature to Fahrenheit Exit CASE 1: Convert Fahrenheit temperature to Celsius -Display the message to ask to enter Fahrenheit degree from the keyboard -Use the following formula to convert to Celsius degree         Celsius Temperature = (Fahrenheit Temperature – 32) * 5/9 ; -Display the output as below: TemperatureConverter_Smith.cpp TEMPERATURE CONVERTER – JAMES...
Write a menu program to have the above options for the polynomials. Your menu program should...
Write a menu program to have the above options for the polynomials. Your menu program should not use global data; data should be allowed to be read in and stored dynamically. Test your output with the data below. Poly #1: {{2, 1/1}, {1, 3/4}, {0, 5/12}} Poly #2: {{4, 1/1}, {2, -3/7}, {1, 4/9}, {0, 2/11}} provide a C code (only C please) that gives the output below: ************************************ *         Menu HW #4 * * POLYNOMIAL OPERATIONS * * 1....
In Python, write a calculator that will give the user the following menu options: 1) Add...
In Python, write a calculator that will give the user the following menu options: 1) Add 2) Subtract 3) Multiply 4) Divide 5) Exit Your program should continue asking until the user chooses 5. If user chooses to exit give a goodbye message. After the user selections options 1 - 4, prompt the user for two numbers. Perform the requested mathematical operation on those two numbers. Round the result to 1 decimal place. Example 1: Let's calculate! 1) Add 2)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT