Question:

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: Sep 18, 2025
  • (C), (A), (B), (D)
  • (C), (A), (D), (B)
  • (B), (A), (D), (C)
  • (C), (B), (D), (A)
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Step 1: Recall Python exception handling structure.
The general structure is: \begin{verbatim} try: # code except Exception: # error handling else: # executes if no error finally: # executes always \end{verbatim}
Step 2: Match given code blocks.
- (C) → try block (start).
- (A) → except block (error handling).
- (D) → else block (executes if no error).
- (B) → finally block (executes always).

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

Questions Asked in CUET exam

View More Questions