Skip to main contentSkip to solution

Arrange the given keywords in the blank spaces in the correct order of their appearance in the code.

try:

n1= int(input("Enter first number"))

n2= int(input("Enter second number"))

quotient= (n1/n2)

except __________:

print("Please enter numbers only")

except __________:

print("n2 can not be zero")

____:

print("Something went wrong")

____:

print( "Bye")

(A). ZeroDivisionError

(B). ValueError

(C). except

(D). finally

Solution

✅ Correct Option: 3

The order is (B), (A), (C), (D).

The first handler prints "Please enter numbers only", so it catches ValueError, which int() raises when the input is not a number. The second handler prints "n2 can not be zero", so it catches ZeroDivisionError, raised by n1/n2 when n2 is 0.

The third blank is a general except: that catches any other error ("Something went wrong"). The last blank is finally:, which always runs, so "Bye" prints in every case.


Option 1 and Option 2: ZeroDivisionError cannot come first, because the first message is about non-numeric input, which is a ValueError.

Option 4: except and finally are keywords, not exception names, so they cannot fill the first two blanks after except.

A bare except: must come after the specific handlers. If it came first, it would catch every error and the later handlers would never run.

Keyboard Shortcuts

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