Skip to main contentSkip to solution

Consider the following code:

___:
  num=50
  demon= int(input("Enter the denominator"))
  quotient=(num/denom)
  print("Division done")
____ZeroDivisionError:
  print("Denominator is zero...not allowed")
___:
  print("The result of division sis", quotient)
___:
  print("Completed")

Arrange the following keywords to be filled in the blank spaces of the above code.

(A) else

(B) except

(C) finally

(D) try

Solution

✅ Correct Option: 1

The blanks must follow the structure of Python exception handling, in this order:

  1. try: holds the code that may raise an error (the input and division).
  2. except ZeroDivisionError: runs only if that error occurs.
  3. else: runs only if the try block finished with no exception, so it prints the result.
  4. finally: runs always, whether or not an exception occurred, so it prints "Completed".

Option 3: else cannot come before except. It must follow all except blocks.

Options 2 and 4: finally must be the last clause, and the block must begin with try.

Keyboard Shortcuts

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