Feb-12-2017, 05:05 PM
Hi Gigs,
Below is a code that I'm working on:
Below is the ouput of the courses.txt file
Below is a code that I'm working on:
def class_tuple_create(filename): try: file = open (filename, 'r') except: print(filename, 'Cannot be opened') else: myDict = {} for line in file: list = line.split() course_id = list[0] room = list[1] name = list[2] time = list[3] class_data = (room, name, time) myDict[course_id] = class_data file.close() return myDict def print_classes(myDict): print ('ID\tRoom\tInstr\tStart') print ('------------------------------') for key in sorted(myDict): print (key, myDict[key]) class_information = class_tuple_create('xxxxx') class_information = class_tuple_create('courses.txt') print_classes(class_information)I was expecting the output below
Output: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
but it's printing the following:Output: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')
Please any advise on how to remove the quotes by printing individual element ?Below is the ouput of the courses.txt file
Output: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