Question

In: Computer Science

Chapter 6: Use a list to store the players Update the program in python so that...

Chapter 6: Use a list to store the players

Update the program in python so that it allows you to store the players for the starting lineup. This

should include the player’s name, position, at bats, and hits. In addition, the program

should calculate the player’s batting average from at bats and hits.

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: 2

Name: Mike

Position: C

At bats: 0

Hits: 0

Mike was added.

Menu option: 1

Player POS AB H AVG

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

1 Joe P 10 2 0.2

2 Tom SS 11 4 0.364

3 Ben 3B 0 0 0.0

4 Mike C 0 0 0.0

Menu option: 6

Lineup number: 4

You selected Mike AB=0 H=0

At bats: 4

Hits: 1

Mike was updated.

Menu option: 4

Current lineup number: 4

Mike was selected.

New lineup number: 1

Mike was moved.

Menu option: 7

Bye!

Specifications

 Use a list of lists to store each player in the lineup.

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

 Make sure that the user’s position entries are valid.

Solutions

Expert Solution

Raw code:

pos=('C', '1B', '2B', '3B', 'SS', 'LF', 'CF', 'RF', 'P')

def display(list):

# f1.display1(list)

print("\tPlayer\tPOS\tAB\tH\tAVG")

j=1

for i in range(len(list)):

if int(list[i][2])==0:

avg=0

else:

avg=round(int(list[i][3])/int(list[i][2]),3)

print(str(j)+'\t'+str(list[i][0])+'\t'+str(list[i][1])+'\t'+str(list[i][2])+'\t'+str(list[i][3])+'\t'+str(avg))

j=j+1

def add1(list):

name=input("Name: ")

p=input("Position:")

while p not in pos:

print("Wrong position, Please enter valid position")

p=input("Position: ")

at=input("At bats: ")

hit=input("Hits: ")

l=[]

l.append(name)

l.append(p)

l.append(at)

l.append(hit)

list.append(l)

print(name,' was added. ')

def remove1(list):

n=int(input("Enter the lineup number to remove: "))

print(list[n-1][0]+' was deleted.')

del list[n-1]

def move(list):

n1=int(input("Enter a current lineup number to move: "))

print(list[n1-1][0]+' was selected. ')

n2=int(input("Enter a new lineup number: "))

print(list[n1-1][0]+' was moved. ')

l=list[n1-1]

list.insert(n2-1,1)

del list[n1]

def editpos(list):

n=int(input("Enter a lineup number to edit: "))

print("You selected " +list[n-1][0]+" POS="+list[n-1][1])

p=input("Enter a new Position: ")

while p not in pos:

print("Wrong position, Please enter valid postion")

p=input("Enter a new Position: ")

list[n-1][1]=p

print(list[n-1][0]+' was updated.')

def editstat(list):

n=int(input("Enter a lineup number to edit: "))

print('You selected ',list[n-1][0])

at=input("Enter new At bats: ")

hit=input("Enter new hits: ")

list[n-1][2]=at

list[n-1][3]=hit

print(list[n-1][0]+' was updated')

def main():

# list=f1.read()

list=[['Joe','P',10,2,0.2],['Tom','SS',11,4,0.364],['Ben','3B',0,0,0.0],['Mike','C',0,0,0.0]]

print("="*64)

print("MENU OPTIONS")

print("1 - Display 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("\nPOSITIONS")

print(pos)

print("="*64)

ch=input("\nMenu option: ")

while ch<='7':

if ch=='1':

display(list)

elif ch=='2':

add1(list)

elif ch=='3':

remove1(list)

elif ch=='4':

move(list)

elif ch=='5':

editpos(list)

elif ch=='6':

editstat(list)

elif ch=='7':

print('Bye!')

exit()

ch=input('\nMenu option: ')

if __name__=="__main__":

main()



Editor;

output:

Hope this helps you! If you still have any doubts or queries please feel free to comment in the comment section.

"Please refer to the screenshot of the code to understand the indentation of the code".

Thank you! Do upvote.


Related Solutions

Chapter 6: Use a list to store the players In Python, Update the program so that...
Chapter 6: Use a list to store the players In Python, Update the program so that it allows you to store the players for the starting lineup. This should include the player’s name, position, at bats, and hits. In addition, the program should calculate the player’s batting average from at bats and hits. Console ================================================================ Baseball Team Manager MENU OPTIONS 1 – Display lineup 2 – Add player 3 – Remove player 4 – Move player 5 – Edit player...
6.23 LAB: Python insert/update sqlite3 datafiles Given is a Python program that connects to a sqlite...
6.23 LAB: Python insert/update sqlite3 datafiles Given is a Python program that connects to a sqlite database and has one table called writers with two columnns: name - the name of a writer num - the number of works the writer has written The writers table originally has the following data: name, num Jane Austen,6 Charles Dickens,20 Ernest Hemingway,9 Jack Kerouac,22 F. Scott Fitzgerald,8 Mary Shelley,7 Charlotte Bronte,5 Mark Twain,11 Agatha Christie,73 Ian Flemming,14 J.K. Rowling,14 Stephen King,54 Oscar Wilde,1...
6.23 LAB: Python insert/update sqlite3 datafiles Given is a Python program that connects to a sqlite...
6.23 LAB: Python insert/update sqlite3 datafiles Given is a Python program that connects to a sqlite database and has one table called writers with two columnns: name - the name of a writer num - the number of works the writer has written The writers table originally has the following data: name, num Jane Austen,6 Charles Dickens,20 Ernest Hemingway,9 Jack Kerouac,22 F. Scott Fitzgerald,8 Mary Shelley,7 Charlotte Bronte,5 Mark Twain,11 Agatha Christie,73 Ian Flemming,14 J.K. Rowling,14 Stephen King,54 Oscar Wilde,1...
use python 1. Write a program that a. defines a list of countries that are members...
use python 1. Write a program that a. defines a list of countries that are members of BRICS (Brazil, Russia, India, China, Sri Lanka) b. Check whether a country is a member of BRICS or not Program run Enter the name of country: Pakistan Pakistan is not a member of BRICS Enter the name of country : India India is a member of BRICS 2. Write a program to create a list of numbers in the range of 1 to...
programming in python Design a program that initializes a list of 5 items to zero (use...
programming in python Design a program that initializes a list of 5 items to zero (use repetition operator). It then updates that list with a series of 5 random numbers. The program should find and display the following data: -The lowest number in the list - Average of the numbers stored in the list
IN PYTHON: Write a program to study countries and their capitals. The program will store country:capital...
IN PYTHON: Write a program to study countries and their capitals. The program will store country:capital information and allow the user to quiz themselves. These two functions are required for this assignment. You may add other functions that you deem appropriate: - menu()   This function, which displays all the user options to the screen, prompts the user for their choice and returns their choice. This function will verify user input and ALWAYS return a valid choice. - addCapital(dict) This function...
Write a Python program that has a list of 5 numbers [2, 3, 4, 5, 6)....
Write a Python program that has a list of 5 numbers [2, 3, 4, 5, 6). Print the first 3 elements from the list using slice expression. a. Extend this program in a manner that the elements in the list are changed to (6, 9, 12, 15, 18) that means each element is times 3 of the previous value. b. Extend your program to display the min and max value in the list.
Write a program in python such that There exists a list of emails List Ls =...
Write a program in python such that There exists a list of emails List Ls = ['[email protected]','[email protected]','[email protected]','[email protected]',[email protected]'] Count the number of emails IDS which ends in "ac.in" Write proper program with proper function accepting the argument list of emails and function should print the number of email IDs and also the email IDS ending with ac.in output 2 [email protected] [email protected] ================================= i am trying like this but getting confused len [True for x in Ls if x.endswith('.ac.in')] please write complete...
USE Python 2.7(screen shot program with output) the task is: takes in a list of protein...
USE Python 2.7(screen shot program with output) the task is: takes in a list of protein sequences as input and finds all the transmembrane domains and returns them in a list for each sequence in the list with given nonpolar regions and returns the lists for those. 1. This code should call two other functions that you write: regionProteinFind takes in a protein sequence and should return a list of 10 amino acid windows, if the sequence is less than...
Use Python to Load a file containing a list of words as a python list :param...
Use Python to Load a file containing a list of words as a python list :param str filename: path/name to file to load :rtype: list
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT