13 — Practice solutions

← Questions

These are independently written explanations, not an official marking scheme.

13A

Results: 3 int; 2 int; -3 int; 2 int; "444" str; 14 int. Floor division rounds the quotient downward, including for negative values.

13B

def boxes_needed(items, capacity):
    boxes = items // capacity
    if items % capacity != 0:  # Only a partial final box adds another box.
        boxes += 1
    return boxes

The expected results are 0, 2, 3. Adding one unconditionally fails for exact multiples and for zero items.