Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create the file hw4.py. Enter the headers for each of the required functions. Under each header write the Python statement pass. Run the script. Fix

  1. Create the file hw4.py. Enter the headers for each of the required functions. Under each header write the Python statement pass. Run the script. Fix any errors you find.
  2. Replace the pass statement in open_file_read with the body of the code from your hw3.py script. Copy the first line of the test code into the bottom of the file. Run the script entering both a real filename and the name of a file that does not exists. Fix any errors you find.
  3. Remove the pass statement from quiz_dictionary_create. Replace it with a statement that creates an empty dictionary named quiz_scores. Write a for loop that loops through the file object file. Inside the for loop write a print statement to print the line. Copy the second line of the test code into the bottom of the file. Run the script.
  4. Remove the print statement. Run split on the line and store it in the variable fields. Print fields. Run the script.
  5. Remove the print statement. Set the variable id to the first element in fields. Print id. Run the script.
  6. Remove the print statement. Create the empty list scores. Write a for loop that loops over the all but the first element of fields. In other words the loop must skip the first element which is an id, not a score. You can do with the range function using indexing. Or you could use a slice. Inside the for loop print each score.
  7. Remove the print statement. Replace it with a statement that adds the element to scores after converting it to an integer. Outside the inner for loop print scores. Run the script.
  8. Replace the print statement with a line that adds an entry to the dictionary quiz_scores. id will be the key and scores will be the value. After the outer for loop print quiz_scores. Run the script.
  9. Remove the print statement. Replace it with a statement that returns quiz_scores. Remove the pass statement from print_dictionary. Replace it with the body of the code from print_dictionary in hw3.py. Add the third line of the test code the bottom of the script. Run the script.
  10. Remove the pass statement from average_dictionary_create. Replace it with a statement that creates an empty dictionary. Write a for loop that loops through the dictionary parameter dict. Use id as the loop variable. Inside the loop create the variable scores and set it equal to the value associated with id. Print scores. Add the next two lines from the test code to the bottom of the script. Run the script.
  11. Remove the print statement. Create the variable total and set it to 0. Use a for loop to iterate through the values in scores. Inside the loop add each element to total. After the loop print total. Run the script.
  12. Remove the print statement. Calculate the average grade and set it equal to the variable average. The value of average must be an integer. Create an entry in the dictionary where id is the key and average is the value. After the outer loop, print the dictionary. Run the script.
  13. Remove the print statement. Replace it with a statement that returns the dictionary. Add the last line of the test code to the bottom of the script. Run the script.

Test code

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

file (quiz_scores.txt)

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 01583835 57 69 66 88 69 77 80 79 53 57 07787151 81 78 61 89 74 73 87 77 92 52

function -

  • open_file_read
  • quiz_dictionary_create
  • average_dictionary_create
  • print_dictionary

def print_dictionary(dict): for entry in sorted() print()

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

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

State the uses of job description.

Answered: 1 week ago

Question

Explain in detail the different methods of performance appraisal .

Answered: 1 week ago

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago