[Solved]Question 2 Errors Often Said Nothing Life Certain Death Taxes Programmer Data Scientist Ho Q37059488


Question 2: Errors It is often said that nothing in life is certain but death and taxes. For a programmer or data scientist, however, nothing is certain but encountering errors. In Python, there are two primary types of errors, both of which you are likely familiar with: syntax errors and exceptions. Syntax errors occur when the proper structure of the language is not followed, while exceptions are errors that occur during the execution of a program. These include errors such as ZeroDivisionError, TypeError, NameError, and Under the hood, these errors are based in the concepts of object orientation, and all exceptions are class objects. If you’re interested in more detailed explanations of the structure of exceptions as well as how to create your own, check out this article from the Python documentation! In the meantime, we’ll implement our own version of an Error class many more! 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 superO function e class Error: err1 Error(12, “error.py”) >errl.write) error.py: 12 def-init-(self, line, file): YOUR CODE HEREk def write(self): return self.filestr(self.line) class SyntaxError (Error): err1 SyntaxError(17, “HW10.py”) err1.write() Hw10.py:17 SyntaxErrorInvalid 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 typeSyntaxError’ msgs 0 “Invalid syntax”, 1: “Unmatched parentheses”, 2: “Incorrect -init-(self, line, file, code-0): def 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): ZeroDivisionError(273 , ру”) erri “HW10 >>> err1.write() Hw10.py:273 ZeroDivisionError : division by zero typeZeroDivisionError’ def init (self.line, file, message ‘division by zero”) “YOUR CODE HEREk” def write(self): endself.type +” self.message YOUR CODE HERE” Show transcribed image text Question 2: Errors It is often said that nothing in life is certain but death and taxes. For a programmer or data scientist, however, nothing is certain but encountering errors. In Python, there are two primary types of errors, both of which you are likely familiar with: syntax errors and exceptions. Syntax errors occur when the proper structure of the language is not followed, while exceptions are errors that occur during the execution of a program. These include errors such as ZeroDivisionError, TypeError, NameError, and Under the hood, these errors are based in the concepts of object orientation, and all exceptions are class objects. If you’re interested in more detailed explanations of the structure of exceptions as well as how to create your own, check out this article from the Python documentation! In the meantime, we’ll implement our own version of an Error class many more! 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 superO function e class Error: err1 Error(12, “error.py”) >errl.write) error.py: 12 def-init-(self, line, file): YOUR CODE HEREk def write(self): return self.filestr(self.line) class SyntaxError (Error): err1 SyntaxError(17, “HW10.py”) err1.write() Hw10.py:17 SyntaxErrorInvalid 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 typeSyntaxError’ msgs 0 “Invalid syntax”, 1: “Unmatched parentheses”, 2: “Incorrect -init-(self, line, file, code-0): def 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): ZeroDivisionError(273 , ру”) erri “HW10 >>> err1.write() Hw10.py:273 ZeroDivisionError : division by zero typeZeroDivisionError’ def init (self.line, file, message ‘division by zero”) “YOUR CODE HEREk” def write(self): endself.type +” self.message YOUR CODE HERE”
Expert Answer
Answer to Question 2: Errors It is often said that nothing in life is certain but death and taxes. For a programmer or data scient… . . .
OR

