Error and Exception Handling · 19 / 20 Exercise Hard

Exception groups

Objective

Since Python 3.11, ExceptionGroup groups several errors into one and except* lets you handle each type separately. It is useful when a task accumulates errors instead of stopping at the first one.

Instructions

  • The input is a line with values separated by spaces. For each value compute 100 // int(value) (integer) and store the result; if it fails with ValueError (not an integer) or ZeroDivisionError (it is zero), store the error in a list and carry on.
  • Show Results: [...] with the list of results. If there are errors, raise an ExceptionGroup with all of them and handle it with except* ValueError and except* ZeroDivisionError, showing ValueError: n and ZeroDivisionError: n with the number of errors of each type (only the types that appeared).
Input
10 x 0 4 y
Output
Results: [10, 25]
ValueError: 2
ZeroDivisionError: 1

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise