Recall & Review
beginner
What is the purpose of the
try block in Python?The
try block contains code that might cause an error. Python runs this code and watches for exceptions (errors).Click to reveal answer
beginner
What happens when an exception occurs inside a
try block?Python stops running the
try block and looks for a matching except block to handle the error.Click to reveal answer
intermediate
What is the role of the
else block in a try–except–else structure?The
else block runs only if the try block did NOT raise any exceptions. It is for code that should run when everything goes well.Click to reveal answer
intermediate
When does the
else block NOT run in a try–except–else structure?The
else block does NOT run if an exception was raised in the try block, even if the exception was caught by except.Click to reveal answer
advanced
Why use
else instead of putting code after the try-except blocks?Using
else clearly shows which code runs only when no errors happen. It keeps the code organized and avoids accidentally running code after an error.Click to reveal answer
What part of try–except–else runs only if no error occurs in the try block?
✗ Incorrect
The else block runs only if the try block completes without any exceptions.
If an exception occurs in the try block and is caught, does the else block run?
✗ Incorrect
The else block does not run if any exception occurs in the try block, even if it is caught.
Where should you put code that must run regardless of errors?
✗ Incorrect
The finally block runs no matter what, whether an exception occurs or not.
What happens if no except block matches the exception raised in try?
✗ Incorrect
If no except block matches, the error is not handled and the program crashes.
Why might you use an else block after try-except?
✗ Incorrect
The else block runs only if no exceptions occur in the try block.
Explain the flow of execution in a try–except–else structure when no exceptions occur.
Think about what happens when everything goes smoothly.
You got /3 concepts.
Describe what happens when an exception is raised and caught in the try–except–else structure.
Focus on how the program handles errors.
You got /3 concepts.