How do named except blocks give ValueError and ZeroDivisionError their own recoveries, and when do else and finally run?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
Two users answered the prompt Tell me a number:. The first typed "12"; the second typed "twelve". Both answers are sitting in responses.
Build results so it holds one entry per response, in order: that response converted with int(), or the string "bug in user input" if the conversion fails. Use a single catch-all except here — you are not naming exception types yet.
Wrapping input in a bare handler
Write the two-number division program, and record that typing the word five gives a ValueError and typing 0 gives a ZeroDivisionError, both turned into one friendly message.
Named except blocks with a catch-all last
Write the version carrying except ValueError, except ZeroDivisionError and a final bare except, then trace the printed output for the run with a = 6 and b = 0.
The else and finally clauses of a try
State that else runs when every line of the try succeeded and finally runs in either case, and record closing files as the standard finally job.
Options available inside an except block
List failing silently with pass, returning flag values, and stopping on your own terms, then write the sum_digits version whose except raises a ValueError carrying a custom message.