Skip to main contentSkip to solution

Write the following Python Program in correct sequence ?

(A) print("Handling exception using try...except...else")

(B) except ZeroDivisonError:

print("Denominator as zero is not allowed")

(C) else :

print("the result of division operation is quotient")

(D)try :

numerator =50

denom=int(input("enter the denominator:"))

quotient=(numerator/denom)

print("Division performed successfully")

Solution

✅ Correct Option: 2

A try block must come first, followed by except, and else comes last. The introductory print statement (A) comes before the whole structure.

(A) print("Handling exception using try...except...else")

(D) try: block with the numerator, input, division and the success message

(B) except ZeroDivisionError: block that handles division by zero

(C) else: block that runs only if the try block raised no exception


Option 4: else cannot come before except. In try...except...else, the else clause must follow all except clauses.

Options 1 and 3: except cannot appear without a try before it, so (B) cannot come before (D).

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question