[Solved]Write Python Program Stores Data Player Team Also Lets Manager Set Starting Lineup Game Nb Q37169107
Write a python program that stores the data for eachplayer on the team, and it also lets the manager set a startinglineup for each game.
NB: Please, can you write the code in Python.Thanks!
Questions:
– Handle the exception that occurs if the program can’t find thedata file.
– Handle the exceptions that occur if the user enters a stringwhere an integer is expected.
– Handle the exception that occurs if the user enters zero forthe number of at bats.
– Thoroughly test the program and update it so it handles allexceptions that you encounter during testing.
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!
Below is the code of the above program in Java, Ibelieve. Can you please translate that code in Python:
import java.util.Scanner; // import the scanner class
public class Game
{
void show() // method to display menu
{
System.out.println(“MENU OPTIONS”);
System.out.println(“1 – Display lineupn2 – Add playern3 – Removeplayern4 – Move playern5 – Edit player positionn6 – Edit playerstatsn7 – Exit program”);
}
void display() // display valid positions
{
System.out.println(“POSITIONSn” +”n” +”C, 1B, 2B, 3B, SS, LF, CF,RF, Pn” +”n” +”Team data file could not be found.n” +”n” +”Youcan create a new one if you want.”);
}
public static void main(String args[])
{
// declaring variables with their default values
String name=””,pos=””;
int bats=0,hits=0;
Scanner sc = new Scanner(System.in); // creating object of scannerclass
Game g = new Game(); // object of main class to call the methods ofgame class
try
{
g.show();
g.display();
while(true) // it will execute unless user exits or an exceptionoccurs
{
System.out.print(“MENU OPTION : “);
int a = sc.nextInt();// it will take input from user (menuopotion)
if(a==1)
{
System.out.println(“Name: “+name+”n” +”Position: “+pos+”n” +”Atbats: “+bats+”n” +
“Hits: “+hits);
g.show();
}
else if(a==2)
{
System.out.print(“Name : “);
name = sc.nextLine();
name = sc.nextLine();
System.out.print(“Position : “);
pos = sc.nextLine();
//checking whether the position entered is correct or not
if(pos.equalsIgnoreCase(“C”) || pos.equalsIgnoreCase(“1b”) ||pos.equalsIgnoreCase(“2b”) || pos.equalsIgnoreCase(“3b”) ||pos.equalsIgnoreCase(“ss”) || pos.equalsIgnoreCase(“lf”) ||pos!=”CF” || pos.equalsIgnoreCase(“rf”) ||pos.equalsIgnoreCase(“P”))
{
System.out.print(“At bats : “);
bats = sc.nextInt();
System.out.print(“Hits : “);
hits = sc.nextInt();
System.out.println(“”+name+” was added”);
g.show();
}
else
{
System.out.println(“not valid option try again”);
g.show();
continue;
}
}
else if(a==3)
{
String t = name;
name = “”;
pos = “”;
bats = 0;
hits = 0;
System.out.print(“”+t+” is removed”);
g.show();
}
else if(a==4)
{
System.out.print(“Position : “);
pos = sc.nextLine();
System.out.print(“”+name+” is moved”);
g.show();
}
else if(a==5)
{
System.out.print(“Position : “);
pos = sc.nextLine();
System.out.print(“”+name+” position is changed”);
g.show();
}
else if(a==6)
{
System.out.print(“Position : “);
pos = sc.nextLine();
System.out.print(“At bats : “);
bats = sc.nextInt();
System.out.print(“Hits : “);
hits = sc.nextInt();
g.show();
}
else if(a==7)
{
System.out.println(“bye”);
System.exit(0);
}
else
{
System.out.println(“not valid option try again”);
g.show();
}
}
}
catch(Exception e) // to catch the exception occured
{
System.out.println(e); // display the exception
}
}
}
Expert Answer
Answer to Write a python program that stores the data for each player on the team, and it also lets the manager set a starting li… . . .
OR

