Ask Question

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)

+2
Answers (1)
  1. 26 January, 20:30
    0
    jersey_dict = {} for i in range (5) : j_num = int (input ("Input Jersey's number (0-99) : ")) rating = int (input ("Input rating (1 - 9) : ")) jersey_dict[j_num] = rating sorted_key = [] for i in jersey_dict. keys () : sorted_key. append (i) sorted_key. sort () for i in sorted_key: print (str (i) + ":" + str (jersey_dict[i]))

    Explanation:

    Firstly, define an empty dictionary (Line 1).

    Next, use a for loop to prompt user to input five Jersey's number and rating and keep the input to the dictionary (Line 3-6). Next, create a list to hold the dictionary keys (Line 8-10). Use build in method, sort to arrange the keys in the list in ascending order (Line 12). At last, print the dictionary element by looping over the value in the sorted_key list (Line 14-15).
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “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 ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers