Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a class in Python, FirstError, that represents an exception. By specifyin

ID: 3571877 • Letter: D

Question

Design a class in Python, FirstError, that represents an exception. By specifying the parent class IDError, objects (values) of this class can be raised and can be caught only where IDErrors or FirstErrors are caught. class FirstError (IDError): Instance variables: ident:: int group:: string (should be either "child" or "color") Methods: init (self, ident, group = "color'):: constructor, initiates all instance variables. str (self):: returns string representation matching this format (based on group and ident) 'color #12345 not found' 'child 2468 not found' repr (self):: returns the same string representations as str

Explanation / Answer

class FirstError(IOError):
   ident = 0
   group = ""

   def __init__(self, ident, group = "color"):
       self.ident = ident
       self.group = group

   def __str__(self):
       return self.group + ' #' + str(self.ident) + ' not found'

   def __repr__(self):
       return self.group + ' #' + str(self.ident) + ' not found'


f = FirstError(12345, 'child')
print f

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote