Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python Write a complete program that, given a literal list of tuples consisting of (name, list of grades) pairs (i.e., the first line of your

python

Write a complete program that, given a literal list of tuples consisting of (name, list of grades) pairs (i.e., the first line of your main should simply be: gradeList = ), prints out a table showing the number of scores and score average for each person, generated in two different ways

Include the following list of tuples for one of your test runs:

[ ('Zaphod', [33, 20]), ('Zaphod', [75, 48]), ('Slartibartfast',[]),

('Trillian', [98, 88]), ('Trillian', [97, 77]), ('Slartibartfast', []),

('Marvin', [2000, 500]) , ('Arthur', [42, 20]), ('Arthur', [64]),

('Trillian', [99]), ('Marvin', [450]), ('Marvin', [550]),

('Agrajag', []), ('Agrajag', []), ('Agrajag', [0]),

('Ford',[50]), ('Ford', [50]), ('Ford', [50]) ]

First set of outputs:Create a dictionary and populate it with the information from the tuples

Write a function named tupleListToDict() to do this

Use each unique name as a dictionary key

The value associated with each key should consist of the list of all grades for the person whose name is the key

If a person's name is not in the dictionary yet and they do not have any grades yet, make their name a key, but set the value for that key to an empty list

Create a list of dictionary keys and sort them

Write a function named getSortedKeyList() to do this

Iterate over the sorted keys

Compute the average of the list of grades for each person

Write a function named computeAverage() to do this

It should take in a list of numeric values and return their average

It should return 0 if the list is empty

Display each name and average in a table

Second set of outputs:

Create a list of tuples from the dictionary using the items() method

Sort the list

Write a function named getSortedListOfTuples() to do this

Iterate over this list

For each item in the list

Get the average of the values in the list portion by invoking computeAverage()

Display the name portion of the item, along with the average of the values as above

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

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions

Question

Describe the sources of long term financing.

Answered: 1 week ago