Question:medium

Arrange the following Python code segments in order with respect to exception handling: (A) except ZeroDivisionError:
\hspace{0.5cm} print("Zero denominator not allowed")
(B) finally:
\hspace{0.5cm} print("Over and Out")
(C) try:
\hspace{0.5cm} n = 50
\hspace{0.5cm} d = int(input("enter denominator"))
\hspace{0.5cm} q = n/d
\hspace{0.5cm} print("division performed")
(D) else:
\hspace{0.5cm} print("Result=", q)

Show Hint

In Python, the correct order of exception handling is: \texttt{try → except → else → finally}.
Updated On: Feb 16, 2026
  • (C), (A), (B), (D)
  • (C), (A), (D), (B)
  • (B), (A), (D), (C)
  • (C), (B), (D), (A)
Show Solution

The Correct Option is B

Solution and Explanation

Step 1: Review Python Exception Handling Syntax.
The standard structure is as follows: \begin{verbatim}try: # Code to be executedexcept Exception: # Code to handle errorselse: # Code to execute if no error occurredfinally: # Code that always executes\end{verbatim}
Step 2: Correlate Code Snippets.
- (C) corresponds to the `try` block (initialization).
- (A) corresponds to the `except` block (error management).
- (D) corresponds to the `else` block (execution upon successful completion).
- (B) corresponds to the `finally` block (guaranteed execution).

Step 3: Determine Correct Sequence.
(C) → (A) → (D) → (B).
Final Answer: \[\boxed{\text{Option (2)}}\]
Was this answer helpful?
0