In: Computer Science
Soccer team roster (Dictionaries) 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.
python
Python code:
#initializing empty dictionary
dic={}
#loop to accept 5 player's details
for i in range(5):
#accepting jersey number
num=int(input("Enter player's jersey number:
"))
#accepting rating
rating=int(input("Enter player's rating:
"))
#adding the details to dictionary
dic[num]=rating
#sorting the key's in dictionary
for i in sorted(dic):
#printing key and value
print(str(i)+" : "+str(dic[i]))
Screenshot:
Input and Output: