What will be the output of the following code (assumes that user enters 0 when denominator is being asked)?
print("Practicing for try block")
try:
numerator=50
denom=int(input("Enter the denominator"))
quotient=(numerator/denom)
print(quotient)
print("Division performed successfully")
except ZeroDivisionError:
print("Denominator as ZERO.... not allowed")
print(“OUTSIDE try..except block”)
What will be the output of the following code (assumes that user enters 0 when denominator is being asked)?
print("Practicing for try block")
try:
numerator=50
denom=int(input("Enter the denominator"))
quotient=(numerator/denom)
print(quotient)
print("Division performed successfully")
except ZeroDivisionError:
print("Denominator as ZERO.... not allowed")
print(“OUTSIDE try..except block”)
Solution
The first line prints "Practicing for try block". Inside the try block, the input 0 makes numerator/denom raise a ZeroDivisionError. Control jumps straight to the except block, so print(quotient) and "Division performed successfully" are skipped. The except block prints "Denominator as ZERO.... not allowed". The last print is outside the try..except, so it still runs and prints "OUTSIDE try..except block".
Option 1: "Division performed successfully" never prints, because the error occurs before that line is reached.
Option 3: the program does not stop after the except block, so the final print still runs.
Option 4: it omits the first print, which always runs before the try block.
Related questions:
2026: 29 May Shift 1
2026: 23 May Shift 2
2025: 21 May Shift 1
2025: 30 May Shift 2