IDLE.
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 ...
def open_file_read(filename):
None
def quiz_dictionary_create(file):
create an empty dictionary
for each line in the file
run split on the line to create the list fields
remove the first element of fields and save it as the student ID
create an empty list scores
for each element in fields
convert the element into an integer
add this integer to scores
return the dictionary
def average_dictionary_create(dict):
for each entry in the dictionary
store the key
get the list of scores
set total to 0
for each score in the list of scores
add score to total
get the average by dividing total by the number of scores
create a dictionary entry with this ID and the average
return the dictionary
def print_dictionary(dict):
file = open_file_read("quiz_scores.txt")
scores = quiz_dictionary_create(file)
print_dictionary(scores)
print()
averages = average_dictionary_create(scores)
print_dictionary(averages)
01583835 [57, 69, 66, 88, 69, 77, 80, 79, 53, 57] 03201438 [68, 50, 71, 71, 83, 95, 64, 62, 83, 96] 03981869 [76, 73, 94, 53, 59, 62, 86, 50, 70, 52] 04352948 [77, 84, 51, 71, 72, 92, 85, 51, 75, 66] 07787151 [81, 78, 61, 89, 74, 73, 87, 77, 92, 52] 01583835 70 03201438 74 03981869 68 04352948 72 07787151 76
pass. pass statement in open_file_read
with the body of the code from your hw3.py
script. pass statement from
quiz_dictionary_create. for loop that loops through the file using the
file object file. for loop write a print statement
to print the line. 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 52Fix any errors you find.
print statement. ['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']Fix any errors you find.
print statement. pop with an
argument of 0. 04352948 03981869 03201438 01583835 07787151Fix any errors you find.
print statement. for loop that loops over the remaining elements
of fields. for loop print each score. 77 84 51 71 ...Run the script.
print statement. for loop print scores. [77, 84, 51, 71, 72, 92, 85, 51, 75, 66] [76, 73, 94, 53, 59, 62, 86, 50, 70, 52] [68, 50, 71, 71, 83, 95, 64, 62, 83, 96] [57, 69, 66, 88, 69, 77, 80, 79, 53, 57] [81, 78, 61, 89, 74, 73, 87, 77, 92, 52]Fix any errors you find.
print statement with a line that adds an entry to the dictionary
quiz_scores. for loop print quiz_scores.
{'04352948': [77, 84, 51, 71, 72, 92, 85, 51, 75, 66], '03981869': [76, 73, 94, 53, 59, 62, 86, 50, 70, 52], ...
Fix any errors you find.
print statement. pass statement from print_dictionary. 01583835 [57, 69, 66, 88, 69, 77, 80, 79, 53, 57] 03201438 [68, 50, 71, 71, 83, 95, 64, 62, 83, 96] 03981869 [76, 73, 94, 53, 59, 62, 86, 50, 70, 52] 04352948 [77, 84, 51, 71, 72, 92, 85, 51, 75, 66] 07787151 [81, 78, 61, 89, 74, 73, 87, 77, 92, 52]Fix any errors you find.
01583835 [57, 69, 66, 88, 69, 77, 80, 79, 53, 57] 03201438 [68, 50, 71, 71, 83, 95, 64, 62, 83, 96] 03981869 [76, 73, 94, 53, 59, 62, 86, 50, 70, 52] 04352948 [77, 84, 51, 71, 72, 92, 85, 51, 75, 66] 07787151 [81, 78, 61, 89, 74, 73, 87, 77, 92, 52] [77, 84, 51, 71, 72, 92, 85, 51, 75, 66] [76, 73, 94, 53, 59, 62, 86, 50, 70, 52] [68, 50, 71, 71, 83, 95, 64, 62, 83, 96] [57, 69, 66, 88, 69, 77, 80, 79, 53, 57] [81, 78, 61, 89, 74, 73, 87, 77, 92, 52]Fix any errors you find.
print statement. for loop to iterate through the values in scores. 01583835 [57, 69, 66, 88, 69, 77, 80, 79, 53, 57] 03201438 [68, 50, 71, 71, 83, 95, 64, 62, 83, 96] 03981869 [76, 73, 94, 53, 59, 62, 86, 50, 70, 52] 04352948 [77, 84, 51, 71, 72, 92, 85, 51, 75, 66] 07787151 [81, 78, 61, 89, 74, 73, 87, 77, 92, 52] 724 675 743 695 764Fix any errors you find.
print statement. round.
01583835 [57, 69, 66, 88, 69, 77, 80, 79, 53, 57]
03201438 [68, 50, 71, 71, 83, 95, 64, 62, 83, 96]
03981869 [76, 73, 94, 53, 59, 62, 86, 50, 70, 52]
04352948 [77, 84, 51, 71, 72, 92, 85, 51, 75, 66]
07787151 [81, 78, 61, 89, 74, 73, 87, 77, 92, 52]
{'04352948': 72, '03981869': 68, '03201438': 74, '01583835': 70, '07787151': 76}
Fix any errors you find.
print statement. 01583835 [57, 69, 66, 88, 69, 77, 80, 79, 53, 57] 03201438 [68, 50, 71, 71, 83, 95, 64, 62, 83, 96] 03981869 [76, 73, 94, 53, 59, 62, 86, 50, 70, 52] 04352948 [77, 84, 51, 71, 72, 92, 85, 51, 75, 66] 07787151 [81, 78, 61, 89, 74, 73, 87, 77, 92, 52] 01583835 70 03201438 74 03981869 68 04352948 72 07787151 76
cd it117/hw/hw4
hw4.py
01583835 [57, 69, 66, 88, 69, 77, 80, 79, 53, 57] 03201438 [68, 50, 71, 71, 83, 95, 64, 62, 83, 96] 03981869 [76, 73, 94, 53, 59, 62, 86, 50, 70, 52] 04352948 [77, 84, 51, 71, 72, 92, 85, 51, 75, 66] 07787151 [81, 78, 61, 89, 74, 73, 87, 77, 92, 52] 01583835 70 03201438 74 03981869 68 04352948 72 07787151 76
Copyright © 2021 Glenn Hoffman. All rights reserved. May not be reproduced without permission.