Create the correct messages when called

Assignment Help Basic Computer Science
Reference no: EM132290154

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):
        "*** YOUR CODE HERE ***"

    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 ***"

Reference no: EM132290154

Questions Cloud

Designed to increase the accuracy of company audits : How would you measure the effectiveness of a training program designed to increase the accuracy of a company’s audits?
What is your forecast of monthly average demand for 2016 : Use the classical decomposition method to forecast average demand for 2016 by month. What is your forecast of monthly average demand for 2016?
Describe the components of a risk management plan : Describe the components of a Risk Management Plan: Risk Identification, Risk Analysis, Risk
Ethics of salary advance united making payday loans : What is your evaluation of the ethics of Salary Advance United making payday loans?
Create the correct messages when called : Complete the Error, SyntaxError, and ZeroDivisionError classes such that they create the correct messages when called.
Create a timeline of practicum activities using given detail : As a future advanced practice nurse, it is important that you are able to connect your classroom experience to your practicum experience.
Find recent survey by national organization : Find a recent survey by a national organization or a news media outlet and look at their sample size and margin of error.
Structured format and numbering in listing : Document a complete list of functional requirements (non-functional requirements are not required). Be specific and describe your requirements in a clear
How does due diligence play into analyzing business : How does due diligence play into analyzing a business?

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Why does ip need fragmentation

Why does IP need fragmentation? Who / What creates Fragments? Who / What reassembles them?

  Evaluate online tutorials and online communities

Ray and Jason have just finished developing the documentation for a system your team recently completed. Ray insists that the documentation should be printed in booklet format and included with the system.

  It audit profession continues to grow

Discuss educational opportunities for those just entering the profession or those looking for growth.

  Slope of the production possibilities curve

The fact that the slope of the production possibilities curve becomes steeper as we move down along the curve indicates what?

  Two main functions of user accounts in a network

What are the two main functions of user accounts in a network?

  Write a program that implements the huffman coding

Traverse the tree to discover the binary encodings of each character. Each left branch represents a ‘0' in the character's encoding and each right branch represents a "1".

  Discuss a job interview you had at some point

Discuss a job interview you had at some point. Do you believe the interviewer asked appropriate questions based on the recommendations you have learned in this course?

  Applications in a language and system independent way

Which is the protocol for performing RPCs between applications in a language and system independent way?

  What would you be willing to pay to play this game

You bet! You roll a die. If it comes up a 6, you win $100. If not, you get to roll again. If you get a 6 the second time, you win $50. If not, you lose.

  Compare three input devices and three output devices

As a computer technician, you must be familiar with a wide range of Input/Output (I/O) devices including; keyboards, mice, monitors, biometric devices, projectors, cameras, and video or graphics cards. Compare three input devices and three output d..

  What is the pmf of n, the number of successful message

what is the PMF of N, the number of successful message transmissions?

  Organization an important business decision

Why is selecting computer hardware and software for the organization an important business decision? What factors should be considered?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd