Question: Deliverables There is one deliverable for this assignment hw4.py Make sure the script obeys all the rules in Homework Script Rules Specification This script must

Deliverables

There is one deliverable for this assignment

  • hw4.py

Make sure the script obeys all the rules in Homework Script Rules

Specification

This script must read in a text file containing a list of students and their scores on quizzes.

The file has entries like the following

04352948 77 84 51 71 72 92 85 51 75 66 03981869 76 73 94 53 59 62 86 50 70 52 03201438 68 50 71 71 83 95 64 62 83 96 ...

The first value on each line is a student ID and the rest are quiz scores.

The script should create two dictionaries and print them.

The keys of both dictionaries are student_id.

The values of the first dictionary must be an list of integer scores for each student.

The values of the second dictionary must be the rounded average of quiz scores for each student.

The script must have 4 functions:

  • open_file_read
  • quiz_dictionary_create
  • average_dictionary_create
  • print_dictionary

open_file_read

This function must have the following header:

def open_file_read(filename):

It must try to create a file object for reading on the file whose name is given by the parameter filename.

If it is succesful in creating the file object it should return the object.

If it is cannot create the object it should print an error message and return None.

quiz_dictionary_create

This function must have the following header:

def quiz_dictionary_create(file):

The function must create a dictionary where the id is the key and a list of grades is the value.

The grades in the list must be stored as integers.

The function must return this dictionary.

average_dictionary_create

This function must have the following header:

def average_dictionary_create(dict):

The function must create a dictionary where the id is the key and the average score is the value.

The average score must be an integer.

The function must return this dictionary.

print_dictionary

This function must have the following header:

def print_dictionary(dict):

The function must print the key and value for each entry in the dictionary sorted by key.

Script for this assignment

Open an a text editor and create the file hw4.py.

You can use the editor built into IDLE or a program like Sublime.

Test Code

Your hw4.py file must contain the following test code at the bottom of the file:

file = open_file_read("quiz_scores.txt") scores = quiz_dictionary_create(file) print_dictionary(scores) print() averages = average_dictionary_create(scores) print_dictionary(averages)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!