Help complete the Error, SyntaxError, and ZeroDivisionError classes
such that they create the correct messages when called.
-The SyntaxError and ZeroDivisionError classes inherit from the Error class and add functionality that is unique to those particular errors. Their code is partially implemented for you.
-The add_code method adds a new helpful message to your error, while the write method should print the output that you see when an error is raised.
-You can access the parent class methods using the super() function
class Error:
“””
>>> err1 = Error(12, “error.py”)
>>> err1.write()
‘error.py:12’
“””
def __init__(self, line, file):
self.line=line
self.file=file
def write(self):
return self.file + ‘:’ + str(self.line)
class SyntaxError(Error):
“””
>>> err1 = SyntaxError(17, “HW10.py”)
>>> err1.write()
HW10.py:17 SyntaxError : Invalid syntax
>>> err1.add_code(4, “EOL while scanning string literal”)
>>> err2 = SyntaxError(18, “HW10.py”, 4)
>>> err2.write()
HW10.py:18 SyntaxError : EOL while scanning string literal
“””
type = ‘SyntaxError’
msgs = {0 : “Invalid syntax”, 1: “Unmatched parentheses”, 2: “Incorrect indentation”, 3: “missing colon”}
def __init__(self, line, file, code=0):
“*** YOUR CODE HERE ***”
def write(self):
end = self.type + ‘ : ‘ + self.message
“*** YOUR CODE HERE ***”
def add_code(self, code, msg):
“*** YOUR CODE HERE ***”
class ZeroDivisionError(Error):
“””
>>> err1 = ZeroDivisionError(273, “HW10.py”)
>>> err1.write()
HW10.py:273 ZeroDivisionError : division by zero
“””
type = ‘ZeroDivisionError’
def __init__(self, line, file, message=’division by zero’):
“*** YOUR CODE HERE ***”
def write(self):
end = self.type + ‘ : ‘ + self.message
“*** YOUR CODE HERE ***”
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code “Newclient”
The post complete the Error, SyntaxError, and ZeroDivisionError classes such that they create the correct messages when called. appeared first on Superb Professors.
Case study one page Case study one page Case study one page Case study one…
Business Calculus quiz that is 10 questions and has an hour time limit. Must be…
Write a 175- to 265-word response to the following: What constitutes “robust interoperability,†and what…
For this News Briefing Quest task , pick and analyze a U.S. political news article…
ACC 610 Milestone TwoGuidelines and Rubric This is the secondof three milestone assignments that will…
Please answer the questions in the attachment. I have sent you the required materials. Send…