Write a Python program that, in a loop, asks the user for a name and then a
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 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.
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill