Self Studies

Computer Science Test - 2

Result Self Studies

Computer Science Test - 2
  • Score

    -

    out of -
  • Rank

    -

    out of -
TIME Taken - -
Self Studies

SHARING IS CARING

If our Website helped you a little, then kindly spread our voice using Social Networks. Spread our word to your readers, friends, teachers, students & all those close ones who deserve to know what you know now.

Self Studies Self Studies
Weekly Quiz Competition
  • Question 1
    5 / -1
    In which working mode, the Python interpreter displays the name of the error and a small description of the error?
    Solution

    The correct answer is option 3.

    Concept:

    In Python, there are two options/methods for running code:

    Interactive mode:

    The interactive mode, often known as the REPL, allows us to quickly run blocks or a single line of Python code. The code is executed using the Python shell, which is included with the Python installation.

    Script mode

    If we need to create a large piece of Python code or if our Python script covers numerous files, we should avoid using interactive mode. In such circumstances, script mode is the way to go. In script mode, we write our code in a text file and save it with the.py (Python) suffix.

    Differences Between Interactive and Script Mode:

    • To receive results in script mode, we must first create and save a file. After pressing the enter key in interactive mode, the result is returned instantly.
    • In script mode, we have a direct means of altering our code. In interactive mode, this is not feasible.

    Hence the correct answer is Shell Mode and Script Mode.

  • Question 2
    5 / -1
    Which statements are used by a user to forcibly raise exceptions in a program?
    Solution

    The correct answer is option 2.

    Concept:

    • Exception Handlers are programs that are designed to run when a specific exception is thrown.
    • Raising an exception involves stopping the usual flow of program execution and navigating to the exception handler. 
    • Raise and assert statements are used to raise exceptions.
    • Raise is often utilized when an erroneous condition has been recognized or when a condition does not fulfilled. Similar to assert, however, the exception is only triggered if a condition is fulfilled.

    Hence the correct answer is raise and assert.

  • Question 3
    5 / -1
    The argument is generally a ____________ that is displayed when the exception is raised.
    Solution

    The correct answer is option 3.

    Concept:

    • The string printed as the exception type is the name of the built-in exception that occurred. This is valid for all built-in exceptions, but need not be true for user-defined exceptions because they are useful for user convention.
    • Standard exception names are built-in identifiers that are not reserved keywords.

    Explanation:

    •  Exceptions are classified according to their type, which is reported as part of the message.
    • The exception types are ZeroDivisionError, NameError, and TypeError.
    • The name of the built-in exception that occurred in the source code of the program. So the argument is generally a string that is displayed when the exception is raised.

    Hence the correct answer is String.

  • Question 4
    5 / -1
    Which type of errors are captured and handled by Exception Handling technique?
    Solution

    The correct answer is option 3.

    Concept:

    • A Python object that describes an error is called an exception or error or runtime error.
    • Runtime Errors are captured and handled by the exception Handling technique in python.

    Explanation:

    Exception handling in Python is a powerful method or approach that allows us to manage runtime errors in a program while maintaining the program's usual flow. All exceptions occur only during runtime. A syntax error happens during the compile time.

    Hence the correct answer is Runtime Errors.

  • Question 5
    5 / -1

    What will be the sequence of output statements for the following code:

    print("Insert positive number")
    def positive(number):
        assert number>=0, "Error: Negative Number"
    print (positive(5))
    print (positive(-5))

    Solution

    The correct answer is option 1.

    Concept:

    The given python snippet is,

    1. print("Insert positive number")
    2. def positive(number):
    3.    assert number>=0, "Error: Negative Number"
    4. print (positive(5))
    5. print (positive(-5))

    Assert statement:

      In Python, the assert statement is used to continue the execution of the specified condition that has been evaluated to True. If the assert condition returns False, the AssertionError exception is raised with the error message specified.

    Python def keyword:

     The Python def keyword is used to define a function; it is used before the name of a function given by the user to construct a user-defined function. A function is a logical unit of code in Python that has a sequence of statements indented under a name specified using the "def" keyword.

    Explanation:

    The print function prints the statement like Insert positive number. Assert condition returns False, the AssertionError exception is thrown with the supplied error message. And prints the none in the function.

    So it gives the error like,

    Insert positive number
    None
    Traceback (most recent call last):
      File "", line 5, in
    File "", line 3, in positive
    AssertionError: Error: Negative Number

  • Question 6
    5 / -1
    This process of creating an exception object and handing it over to the runtime system is know as _______________.
    Solution

    The correct answer is option 3.

    Concept:

    • When a method encounters an error, the method produces an object. The object, known as an exception object, contains information about the error, such as its kind and the program's state at the time the error occurred.
    • Throwing an exception is the act of creating an exception object and passing it to the runtime system. When a method throws an exception, the runtime system looks for a way to manage it.
    • It is as easy as using the "throw" command to throw an exception. Then you provide the Exception object that you want to throw. Every Exception has a message that contains a human-readable error explanation. It is frequently tied to issues with user input, the server, the backend, and so on.

    ​Hence the correct answer is throwing an exception.

  • Question 7
    5 / -1
    Throwing an Exception executes in which of the following sequence:
    Solution

    The correct answer is option 2.

    Concept:

    When an error occurs within a method, the method creates an object and hands it off to the runtime system.

    Throwing an Exception executes in the following sequence:

    • Create an exception object. Users can define custom exceptions by creating a new class. This exception class has to be derived, either directly or indirectly, from the built-in Exception class. Most of the built-in exceptions are also derived from this class.
    • The exception is raised. If an exception occurs during the execution of the try clause, the exception may be handled by an except clause. If the exception is not handled by an except clause, the exception is re-raised after the finally clause has been executed.
    • Searches for an exception handler. Catch clauses are looked for in order to find one that can handle the exception. When an exception is handled by a catch clause, the catch block is performed.

    Hence the correct answer is Create exception object > Exception is raised > Searches for the exception handler.

  • Question 8
    5 / -1
    The _____________ keeps track of the exact position where the error has occurred.
    Solution

    The correct answer is option 4.

    Concept:

    The interpreter takes statements of a program and executes them.

    Exception: 

    When a Python script finds a condition that it cannot handle, it throws an exception. A Python object that reflects an error is known as an exception.

    Explanation:

    • The compiler or interpreter records the exact spot where the mistake occurred. The compiler displays all errors after compilation, on the other hand, the Interpreter displays errors of each line one by one.
    • The compiler takes an entire program whereas the Interpreter takes a single line of code.
    • The Interpreter keeps track of the exact position where the error has occurred because it displays errors of each line one by one.

    ​Hence the correct answer is Interpreter.

  • Question 9
    5 / -1

    Which error will be raised for the following code:

    marks = 2
    a = marks / 0

    Solution

    The correct answer is option 2.

    Exception ZeroDivisionError:

    When the second parameter to a division or modulo operation is 0, this value ZeroDivisionError is raised. The related value is a string containing information about the operands and the operation.

    The given source code is,

    marks = 2
    a = marks / 0

    Explanation:

    The variable mark is assigned with a value of 2. Now, this mark variable is divided by zero and the result of this operation will stored into a variable a.

    It is basically 2/0 means dividing by zero it gives an exception ZeroDivisionError. 

    ZeroDivisionError occurs when a number is divided by a zero. In Mathematics, when a number is divided by a zero, the result is an infinite number. It is impossible to write an Infinite number physically. Python interpreter throws “ZeroDivisionError: division by zero” error if the result is an infinite number.

    Hence the correct answer is ZeroDivisionError.

    Additional Information

    • IOError stands for Input/Output Error. It happens when the file, file path, or OS activity we're requesting doesn't exist.
    • Division​ZeroError there is no such exception in python.
    • The syntax error exception occurs when the code does not conform to Python keywords, naming style, or programming structure.
  • Question 10
    5 / -1
    An error raised during program execution, even if the program is syntactically and semantically correct, is know as ____________.
    Solution

    The correct answer is option 4.

    Concept:

    Exceptions:

     An exception is an undesired or unexpected occurrence that occurs during program execution, i.e. during run time, and disturbs the usual flow of the program's instructions.

    • The software can catch and handle exceptions. When an exception occurs within a method, an object is created. This object is referred to as the exception object.
    • An exception is an occurrence that happens during program execution that disturbs the regular flow of the program's instructions.
    • An error raised during program execution, even if the program is syntactically and semantically correct, is known as an exception.

    Hence the correct answer is exceptions.

    Additional Information

    • Faults or  Errors can be caused by hardware or software. An error is a component of a system that causes it to fail.
    • A syntax error occurs when a programmer writes an erroneous line of code. Most syntax problems are caused by missing punctuation or a misspelled name.
    • A semantic error arises when a statement is syntactically correct but does not perform the function anticipated by the programmer.
Self Studies
User
Question Analysis
  • Correct -

  • Wrong -

  • Skipped -

My Perfomance
  • Score

    -

    out of -
  • Rank

    -

    out of -
Re-Attempt Weekly Quiz Competition
Self Studies Get latest Exam Updates
& Study Material Alerts!
No, Thanks
Self Studies
Click on Allow to receive notifications
Allow Notification
Self Studies
Self Studies Self Studies
To enable notifications follow this 2 steps:
  • First Click on Secure Icon Self Studies
  • Second click on the toggle icon
Allow Notification
Get latest Exam Updates & FREE Study Material Alerts!
Self Studies ×
Open Now