IDLE
.
def open_file_read(filename):
try/except
statement
def class_dictionary_create(file):
CS101 3004 Haynes 8:00 CS102 4501 Smith 9:00 CS103 6755 Rich 10:00 NT110 1244 Burke 11:00 CM241 1411 Lee 13:00
create the empty dictionary class_dict
loop through the file
create the list fields by running split
on each line
set the variable class_id to the fields entry with index 0
set the variable room to the fields entry with index 1
set the variable instr to the fields entry with index 2
set the variable start to the fields entry with index 3
create the tuple class_data using the variables room, instr and start
make an entry in class_dict with class_id as the key and class_data as the value
return class_dict
def print_classes(class_dict):
open_file_read("xxxxx") file = open_file_read("classes.txt") class_dictionary = class_dictionary_create(file) print_classes(class_dictionary)
Cannot open xxxxx ID Room Instr Start ----------------------------------- CM241 1411 Lee 13:00 CS101 3004 Haynes 8:00 CS102 4501 Smith 9:00 CS103 6755 Rich 10:00 NT110 1244 Burke 11:00
pass
. pass
statement from
open_file_read. try/except
statement. except
clause print an error message. Cannot open xxxxx
pass
statement from
class_dictionary_create. for
loop
that prints each line in the file. split
on the line. pass statement from print_classes
and replace it with a statement that prints the parameter
class_dict. for
loop on the sorted dictionary
class_info using
class_id as the loop variable. for
loop that print labels for each column. for
loop. Cannot open xxxxx ID Room Instr Start ----------------------------------- CM241 1411 Lee 13:00 CS101 3004 Haynes 8:00 CS102 4501 Smith 9:00 CS103 6755 Rich 10:00 NT110 1244 Burke 11:00
cd it117/hw/hw3
python3 hw3.py
Error: Unable to open xxxxx ID Room Instr Start ------------------------------- CM241 1411 Lee 13:00 CS101 3004 Haynes 8:00 CS102 4501 Smith 9:00 CS103 6755 Rich 10:00 NT110 1244 Burke 11:00
Copyright © 2022 Glenn Hoffman. All rights reserved. May not be reproduced without permission.