17.19 Ch 8 Program: Soccer team roster (Dictionaries) (Python 3) This program wi
ID: 3830546 • Letter: 1
Question
17.19 Ch 8 Program: Soccer team roster (Dictionaries) (Python 3)
This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team.
(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. (3 pts)
Ex:
(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. (2 pts)
Ex:
(3) Implement the "Output roster" menu option. (1 pt)
Ex:
(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. (1 pt)
Ex:
(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). (1 pt)
Ex:
(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. (1 pt)
Ex:
(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. (2 pts)
Ex:
Explanation / Answer
def add(d):
n = input("Enter a new player's jersey number:")
r = input("Enter the player's rating:")
if n in d.keys():
print("The player exists in the roster.")
return d
d[n] = r
return d
def add1(d,i):
n = input("Enter the jersey number for player "+str(i)+":")
r = input("Enter the rating for player "+str(i)+":")
if n in d.keys():
print("The player exists in the roster.")
return [d,i]
d[n] = r
return [d,i+1]
def rmv(d):
n = input("Enter a player's jersey number:")
if n in d.keys():
del d[n]
return d
print("There is no such player.")
return d
def output(d):
l = sorted(d.keys())
print("ROSTER")
for i in l:
print("Jersey number: "+str(i)+", Rating: "+str(d[i]))
def outputr(d):
r = input("Enter a rating:")
print("ABOVE "+str(r))
l = sorted(d.keys())
for i in l:
if(d[i]>r):
print("Jersey number: "+str(i)+", Rating: "+str(d[i]))
def update(d):
n = input("Enter a player's jersey number:")
r = input("Enter the player's new rating:")
if n not in d.keys():
print("The player does not exist in the roster.")
return d
d[n] = r
return d
d= {}
i=1
l=[{},6]
while(i<6):
l = add1(d,i)
d = l[0]
i = l[1]
output(d)
while(True):
s = """MENU
a - Add player
d - Remove player
u - Update player rating
r - Output players above a rating
o - Output roster
q - Quit
Choose an option:"""
c = str(input(s))
#print(c)
if(c == "q"):
break
elif(c == "a"):
d = add(d)
elif(c == "d"):
d = rmv(d)
elif(c == "u"):
d = update(d)
elif(c == "r"):
outputr(d)
elif(c == "o"):
output(d)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.