Python Programming (2180711) MCQ

MCQs of Testing, Debugging, Exceptions and Assertions

MCQ No - 1

How many except statements can a try-except block have?

(A) zero
(B) one
(C) more than one
(D) more than zero

D
MCQ No - 2

When will the else part of try-except-else be executed?

(A) always
(B) when an exception occurs
(C) when no exception occurs
(D) when an exception occurs in to except block

C
MCQ No - 3

Is the following Python code valid?
try:
    # Do something
except:
    # Do something
finally:
    # Do something

(A) no, there is no such thing as finally
(B) no, finally cannot be used with except
(C) no, finally must come before except
(D) yes

B
MCQ No - 4

Is the following Python code valid?
try:
    # Do something
except:
    # Do something
else:
    # Do something

(A) no, there is no such thing as else
(B) no, else cannot be used with except
(C) no, else must come before except
(D) yes

D
MCQ No - 5

Can one block of except statements handle multiple exceptions?

(A) yes, like except TypeError, SyntaxError [,…]
(B) yes, like except [TypeError, SyntaxError]
(C) no
(D) none of the mentioned

A