Site icon i2tutorials

Python-Exception-Handling-Quiz

This Quiz contains totally 10 Questions each carry 1 point for you.

1. Which exception is raised when a calculation exceeds maximum limit for a numeric type?
StandardError
ArithmeticError
OverflowError
FloatingPointError

Correct!

Wrong!

2. Can one block of except statements handle multiple exception?

 
yes, like except TypeError, SyntaxError [,…]
yes, like except [TypeError, SyntaxError]
No
None of the above

Correct!

Wrong!

3. When do the else part of try-except-else be executed?
always
when an exception occurs
when no exception occurs
when an exception occurs in except block

Correct!

Wrong!

4. Is the following Python code valid?
try:
    # Lines of code
except:
    # Lines of code
finally:
    # Lines of code
no, there is no such thing as finally
no, finally cannot be used with except
no, finally must come before except
yes

Correct!

Wrong!

5. When is the finally block executed?
when there is no exception
when there is an exception
only when some condition that has been specified is satisfied
always

Correct!

Wrong!

6. What will be the output of the following Python code?
def a():
    try:
       f(x, 4)
    finally:
       print('after f')
    print('after f?')
a()
No output
after f?
error
after f

Correct!

Wrong!

7. What will be the output of the following Python code?
def f(x):
    for i in range(5):
        yield i
g=f(8)
print(list(g))
[0, 1, 2, 3, 4]
[1, 2, 3, 4, 5, 6, 7, 8]
[1, 2, 3, 4, 5]
[0, 1, 2, 3, 4, 5, 6, 7]

Correct!

Wrong!

8. What will be the output of the following Python code if the input entered is 6?
valid = False
while not valid:
    try:
       n=int(input("Enter a number"))
        while n%2!=0:
           print("Bye")
        valid = True
 except ValueError:
        print("Invalid")
Bye (printed once)
No output
Invalid (printed once)
Bye (printed infinite number of times)

Correct!

Wrong!

9. Which of the following statements is true?
The standard exceptions are being automatically imported into Python programs
All raised standard exceptions are to be handled in Python
Asemantic error is thrown when there is a deviation from the rules of a programming language
else block is executed, if any exception is thrown in try block

Correct!

Wrong!

10. An exception is ____________
an object
a special function
a standard module
a module

Correct!

Wrong!

Share the quiz to show your results !

Subscribe to see your results

Ignore & go to results

Python-Exception-Handling-Quiz

You got %%score%% of %%total%% right

%%description%%

%%description%%

Where to go ?

Quizzes

Loading...

Exit mobile version