🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Reviewing AI Code: all 10 questions

Quiz: Reviewing AI Code · Question 9 of 10

In getdiscount, what should replace except Exception: return 0?

In get_discount, what should replace except Exception: return 0?

  1. A.except KeyError: return 0, so that real bugs like a None code still raise an error
  2. B.except: pass
  3. C.Remove the dictionary
  4. D.except Exception: return 50
Answer & explanation

Correct answer: except KeyError: return 0, so that real bugs like a None code still raise an error

Catch only the specific error you expect.

Can you get the rest right without peeking?

Take the timed Quiz: Reviewing AI Code quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →