← Quiz: Exceptions and Files: all 15 questions
Quiz: Exceptions and Files · Question 4 of 15
What does this print? (code)
What does this print?
try:
x = [1, 2][5]
except IndexError:
print("bad index")
else:
print("ok")
- A.bad index
- B.ok
- C.bad index and ok
- D.Nothing
Answer & explanation
Correct answer: bad index
Index 5 is out of range, so the except block runs and else is skipped.
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 →