View the step-by-step solution to:

Something is preventing this python code from running properly. The specifications are below the code.

Something is preventing this python code from running properly. Can you please go through it and improve it so it can work. The specifications are below the code. Thanks

list1=[]

list2=[]

def add_player():

  d={}

  name=input("Enter name of the player:")

  d["name"]=name

  position=input ("Enter a position:")

  if position in Pos:

    d["position"]=position

  at_bats=int(input("Enter AB:"))

  d["at_bats"] = at_bats

  hits= int(input("Enter H:"))

  d["hits"] = hits

  d["AVG"]= hits/at_bats

  list1.append(d)

def display():

  if len(list1)==0:

    print("{:15} {:8} {:8} {:8} {:8}".format("Player", "Pos", "AB", "H", "AVG"))

  print("ORIGINAL TEAM")

  for x in list1:

    #print (list1)

    print("-"*64)

    print(" | " +x["name"]+" | " +x["position"]+" | "+str(x["at_bats"])+" | "+str(x["hits"])+" | " + "%.3f"%(x["AVG"]))

    print("-"*64)

def remove_player():

  name=input("Enter name of the player:")

  for x in list1:

    for k in x.keys():

      if name==x[k]:

        i=list1.index(x)

        del list1[i]

  #print(list1)

def edit_player_position():

  name=input("Enter name of the player:")

  new_position=input("Enter New Position:")

  for x in list1:

    for k in x.keys():

      if name ==x[k]:

        i=list1.index(x)

        list1[i]["position"]=new_postion

  #print(list1)

def edit_player_stats():

  name=input("Enter name of the player:")

  new_at_bats=int(input("Enter new AB:"))

  new_hits=int(input("Enter new H:"))

  for x in list1:

    for k in x.keys():

      if name ==x[k]:

        i=list1.index(x)

        list1[i]["at_bat"]= new_at_bats

        list1[i]["hits"]= new_hits

        list1[i]["AVG"]= new_hits/new_at_bats

  #print(list1)

def move_player():

  name=input("Enter name of the player:")

  new_position=input("Enter New Position:")

  for x in list1:

    for k in x.keys():

      if name ==x[k]:

        i=list1.index(x)

        p=list1.pop(i)

        list2.append(p)

  #print(list1)

  #print(list2)

  display()

  print("Move to new team")

  for x in list2:

    print("-"*64)

    print(" | " +x["name"]+" | " +x["position"]+" | "+str(x["AB"])+" | "+str(x["hits"])+" | " + "%.3f"%(x["AVG"]))

    print("-"*64)

Pos=("C", "1B", "3B", "SS", "LF", "CF", "RF", "P")

ans ="y"

print("POSITIONS:")

for x in Pos:

  print (x,end=",")

print()

while ans =="y":

  print("-"*64)

  print("Baseball Team Manager")

  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")

  ch=int(input ("Enter your choice:"))

  if ch==1:

    display()

  elif ch==2:

    add_player()

  elif ch==3:

    remove_player()

  elif ch==4:

    move_player()

  elif ch==5:

    edit_player_position()

  elif ch==6:

    edit_player_stats()

  elif ch==7:

    print ("Bye!")

   

  else:

    pass

  ans=input("Do you want to continue...(y/n)?")

   

print("Thanks!")



Improve number and string formatting

Update the program to improve the formatting of the numbers and the strings.

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

POS

AB

H

AVG

Player

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

1

Denard Span

CF

545

174

0.319

2

Brandon Belt

1B

533

127

0.238

3

Buster Posey

C

535

176

0.329

4

Hunter Pence

RF

485

174

0.359

5

Brandon Crawford

SS

532

125

0.235

6

Eduardo Nunez

3B

477

122

0.256

7

Joe Panik

2B

475

138

0.291

8

Jarrett Parker

LF

215

58

0.270

9

Madison Bumgarner

P

103

21

0.204

Menu option: 7

Bye!

!!Specifications !! 

-Use the multiplication operator to make sure that horizontal separator lines use 64 characters

-Use spaces, not tabs, to align columns. This should give the program more control over how the columns are aligned.

-Make sure the program always displays the batting average with 3 decimal places. Display the positions by processing the tuple of valid positions.

Top Answer

There were some "input taking" and "printing in a correct way" errors. I've fixed them and also attached the screenshot. Here... View the full answer

Screenshot 2019-05-05 at 12.57.19 PM.png

38f9d370f825: Documents arorc$ python 1.py
POSITIONS:
C, 1B , 3B , SS , LF , CF , RF , P
Baseball Team Manager
MENU OPTIONS :
Display lineup
2
- Add player
Remove player
- Move player
5
Edit player...

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online