Questions in notes
class StudentsDataException(Exception): pass # there pass yes pass all exception, Why do you need the following code raise exception?class BadLine(StudentsDataException): def __init__(self, line_number, line_string): super().__init__(self) self.line_number = line_number self.line_string = line_string This class What is the specific role of , Can you explain the function of each code class FileEmpty(StudentsDataException): def __init__(self): super().__init__(self)from os import strerrordata = { }file_name = input("Enter student's data filename: ")line_number = 1try: f = open(filename, "rt") lines = f.readlines() f.close() if len(lines) == 0: raise FileEmpty() for i in range(len(lines)): line = lines[i] columns = line.split() if len(columns) != 3: raise BadLine(i + 1, line)# Can you explain (i+1,line) What's the situation student = columns[0] + ' ' + columns[1] try: points = float(columns[2]) except ValueError: raise BadLine(i + 1, line) try: #print(data[student]), here print Nothing at all , Just want to see if it can print what data[student] += points# Want to know data[student] Start is not 0 except KeyError: data[student] = points#keyerror There is no mapping object , there “data[student] = points” What does it mean for student in sorted(data.keys()): print(student,'\t', data[student])except IOError as e: print("I/O error occurred: ", strerror(e.errno))except BadLine as e: print("Bad line #" + str(e.line_number) + " in source file:" + e.line_string)except FileEmpty: print("Source file empty")""" The contents of the document :John Smith 5Anna Boleyn 4.5John Smith 2Anna Boleyn 11Andrew Cox 1.5 final output yes Andrew Cox 1.5Anna Boleyn 15.5John Smith 7.0"""