🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Exceptions and Files: all 15 questions

Quiz: Exceptions and Files · Question 11 of 15

What does this print? (code)

What does this print?

def safe_divide(a, b):
    try:
        return a / b
    except ZeroDivisionError:
        return "cannot divide by zero"
    finally:
        print("done", end=" ")

print(safe_divide(10, 0))
  1. A.cannot divide by zero
  2. B.done
  3. C.done cannot divide by zero
  4. D.cannot divide by zero done
Answer & explanation

Correct answer: done cannot divide by zero

finally runs before the function actually returns, so "done" is printed first.

Can you get the rest right without peeking?

Take the timed Quiz: Exceptions and Files quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →