Question: Write a Python program that, in a loop, asks the user for a name and then a numerical score, and then asks whether to do

Write a Python program that, in a loop, asks the user for a name and then a numerical score, and then asks whether to do another. The user may enter the same name more than one time. When a name is entered, check in the name is already in the dictionaries keys. If it is not (if it's a new name), then add a new pair to the dictionary consisting of the name as the key and the entered score inside a list as the value. If the name is already among the dictionary keys (the name already has one or more scores stored for it), then append the current entered score to the end of the list for that name. When the user is done entering names and scores, create a sorted list of the names. Then, using the sorted list, neatly print out each name and the average score for that name. See the sample output below for an adequate implementation.

Experiment with Python dictionaries and their keys() member function that returns a list of a dictionary's keys. You can check if a particular key is in a dictionary by using the in test with the keys list. For example, if our dictionary is

   

MyDict = { 1: 'One', 2: 'Two', 3: 'Three' }

   

Then

   

( 2 in MyDict.keys() ) evaluates to True.

Step by Step Solution

3.39 Rating (165 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Python Code scoresdict while True name inputEnter a name score floatinputEnter a score if name in sc... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!