Close Up After Every Item

Python for AIMedium+10 XP+10

Close Up After Every Item

A machine splits 100 sweets evenly into bags. For each number in bag_counts, it works out how many sweets go in each bag with 100 // count.

Write run_batch(bag_counts) that builds and returns a log, a list of text lines. For each count, in order:

  1. if 100 // count works, add the result as text, like "20"
  2. if it raises a ZeroDivisionError, add "no bags"
  3. either way, add "done" afterwards, using a finally block

Examples

bag_counts = [5, 0]
returns ['20', 'done', 'no bags', 'done']
bag_counts = []
returns []

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run