13 — Practice solutions
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.
Reasoning
Do not use truncation for the negative quotient: floor means round downward. Check remainder through
a = quotient × divisor + remainder. String repetition concatenates copies rather than multiplying a numeric value; multiplication precedes addition in the final expression.
13B
def boxes_needed(items, capacity):
boxes = items // capacity
if items % capacity != 0: # Only a partial final box adds another box.
boxes += 1
return boxesThe expected results are 0, 2, 3. Adding one unconditionally fails for exact multiples and for zero items.
Reasoning
Integer division counts completely filled boxes; a nonzero remainder needs one additional box. The given nonnegative/positive input conditions make this decomposition valid. Do not add an extra box when items is 0 or an exact multiple.