Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Storing data and adding to data in a dictionary: Experiment with Python dictionaries and their keys() member function that returns a list of a dictionary's

Storing data and adding to data in a dictionary: 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, indicating that 2 is a valid key for MyDict.

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.

C:\Users\brokow\UCM Classes\ME 021\2019 Spring Assignments>HW04_02.py

Enter a name: Jimbo

Enter a score for Jimbo: 15

Enter more data (y/n) ? y

Enter a name: Jolene

Enter a score for Jolene: 21

Enter more data (y/n) ? y

Enter a name: Carlos

Enter a score for Carlos: 19

Enter more data (y/n) ? y

Enter a name: Jolene

Enter a score for Jolene: 22

Enter more data (y/n) ? y

Enter a name: Jimbo

Enter a score for Jimbo: 18

Enter more data (y/n) ? n

Carlos has average score 19.00

Jimbo has average score 16.50

Jolene has average score 21.50

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions

Question

describe the main employment rights as stated in the law

Answered: 1 week ago