Python Programming Quiz

Quiz on Try and Except in Python

Time left: 300 seconds

Q.1. A syntax error is a type of ______ error

Select Your Option

A compile-time error generally refers to the errors that correspond to the semantics or syntax.

Q.2. Which error is given out if there is a a mathematical error in the program?

Select Your Option

The arithmetic error occurs when an error is encountered during numeric calculations in Python.

Q.3. Which type of error will be given out
          
            print("Hello World"
          
          

Select Your Option

The Python SyntaxError occurs when the interpreter encounters invalid syntax in code. Here, the print statement is missing the closing ')' parenthesis.

Q.4. The program in which error may occur is written in the except block

Select Your Option

The program in which error may occur is written in the try block and the code to handle the error is written in the except block.

Q.5.Which keyword is used to intentionally create an exception or error?

Select Your Option

The raise keyword is used to raise an exception.

Q.6. What is the output of following program?
          
            a=5
            b = int(input("Enter value of b:"))
            try:
                print(a/b)
            except ArithmeticError:
                print("Error")
          
          

Select Your Option

When the value of b is 0, which raises an ArtihmeticError called ZeroDivisionError.

Q.7. Can one Except statement handle multiple exceptions?

Select Your Option

We can use a tuple of values to specify multiple exceptions in an except clause.

Q.8. The else part of try-except-else runs when

Select Your Option

The else part is executed when no exception occurs.

Q.9. What is the error raised when a built-in function is inputted with invalid data type?

Select Your Option

TypeError is an exception that occurs when the data type of an object in an operation is inappropriate

Q.10. The else keyword can be used to convey to the user a message of?

Select Your Option

The else block of code is executed when there are no errors or exceptions.

Q.11. The try-except blocks can have multiple Except Statements

Select Your Option

It is possible to have multiple except blocks for one try block.

Q.12. What is the base class for all built-in exceptions?

Select Your Option

The BaseException is the base class of all other exceptions.

Q.13. The finally block is exceuted when

Select Your Option

The finally block always executes when the try block exits. This ensures that the finally block is executed even if an unexpected exception occurs.

Q.14. What is the output of the following snippet of code?
          
            try:
                print(1)
            finally:
                print(2)
          
          

Select Your Option

Once the try block executes, 1 is printed. The finally block is then excuted, printing 2.

Q.15. What is the output of the following snippet of code?
          
            l = [1,2,3,4,5]
            print(l[5])
          
          

Select Your Option

The IndexError occurs when an attempt is made to access an item in a list at an index which is out of bounds.

Instructions:-

  1. This Quiz is based on Try and Except in Python
  2. Each correct answer will carry 2 points
  3. Once an option is selected you cannot select any other, So choose wisely
  4. Do not refresh the page as it will reset the quiz
  5. Once the time is up the quiz will automatically get submitted with no of Question responded
  6. Your total score alongwith your name will be shown after submission of the Quiz
  7. Wish you ALL THE BEST 👍👍

START

Results:-

Hi




Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post