← 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))
- A.cannot divide by zero
- B.done
- C.done cannot divide by zero
- 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 →