Question
Need help fixing this code for my python class. These are the directions, the code i currently have and the error I am getting. Thank
Need help fixing this code for my python class. These are the directions, the code i currently have and the error I am getting. Thank you!
(1) Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jersey numbers and the ratings in a dictionary. Output the dictionary's elements with the jersey numbers in ascending order (i.e., output the roster from smallest to largest jersey number). Hint: Dictionary keys can be stored in a sorted list.
(2) Implement a menu of options for a user to modify the roster. Each option is represented by a single character. The program initially outputs the menu, and outputs the menu after a user chooses an option. The program ends when the user chooses the option to Quit. For this step, the other options do nothing.
(3) Implement the "Output roster" menu option.
(4)Implement the "Add player" menu option. Prompt the user for a new player's jersey number and rating. Append the values to the two vectors
(5) Implement the "Delete player" menu option. Prompt the user for a player's jersey number. Remove the player from the roster (delete the jersey number and rating)
(6) Implement the "Update player rating" menu option. Prompt the user for a player's jersey number. Prompt again for a new rating for the player, and then change that player's rating.
(7) Implement the "Output players above a rating" menu option. Prompt the user for a rating. Print the jersey number and rating for all players with ratings above the entered value.
d={} for i in range(5): jersey=int(input("Enter player %s's jersey number: " % str(i+1))) rating=int(input("Enter player %s's rating: " % str(i+1)))
if jersey not in d: d[jersey]=rating print()
print("ROSTER") for k,v in sorted(d.items()): print("Jersey number: %d, Rating: %d" % (k,v))
print()
print('MENU') while True:
print('a - Add player') print('d - Remove player') print('u - Update player rating') print('r - Output players above a rating') print('o - Output roster') print('q - Quit')
choice=input(' Choose an option: ')
choice=choice.lower()
if choice=='o':
print("ROSTER") for k,v in sorted(d.items()): print("Jersey number:%d,Rating:%d" % (k,v))
elif choice=='a':
jersey=int(input("Enter a new player jersey number: ")) rating=int(input("Enter player's rating: "))
if jersey not in d: d[jersey]=rating else: print(" The Player already in the list")
elif choice== 'd':
jersey=int(input(" Enter a jersey number: "))
if jersey in d: del d[jersey] else: print(" The Player is not in the list")
elif choice== 'u':
jersey=int(input(" Enter a jersey number: "))
if jersey in d: rating=int(input(" Enter a new rating for the player: ")) d[jersey]=rating else: print(" The Player is not in the list")
elif choice== 'r':
rating=int(input(" Enter a rating: "))
for k,v in sorted(d.items()):
if v > rating: print("Jersey number:%d,Rating:%d" % (k,v))
elif choice=='q': break else: print(" Enter a valid choice")
ROSTEER Jersey number: 4, Rating: 5 Jersey number: 23, Rating: 4 Jersey number: 30, Rating: 2 Jersey number66, Rating: 9 Jersey number: 84, Rating: , MENU+ a - Add player d Remove player u - Update player rating r Output players above a rating+ oOutput roster q-Quit- Choose an option: Enter a new player jersey number: Enter player's rating: a -Add player. d - Remove player u - Update player rating. r Output players above a rating oOutput roster q -Quit Your output ends with Choose an option: ROSTER Jersey number:4,Rating :5 Jersey number:23, Rating :4 Jersey number: 30,Rating:2 Jersey number: 55, Rating:6 Jersey number : 66, Rating: 9 Jersey number: 84,Rating: 7 a - Add player dRemove player u-Update player rating r-Output players above a oOutput roster rating Quit Choose an option: ROSTEE Jersey number: 4, Rating: 5 Jersey number: 23, Rating: 4 Jersey number: 30, Rating: 2 Jersey number: 55, Rating: 6 Jersey number: 66, Rating: Jersey number: 84, Rating: Expected output M ends with ENU aAdd player dRemove player uUpdate player rating r-Output players above a rating o-Output roster Quit Choose an optionStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started