1
2
3
4
5
6
7
8
9
10
11
def invoice_total(items, discount_percent=0):
if not isinstance(discount_percent, int) or not 0 <= discount_percent <= 100:
raise ValueError("Discount must be an integer from 0 to 100")
subtotal = 0
for item in items:
price, quantity = item["unit_cents"], item["quantity"]
if not isinstance(price, int) or not isinstance(quantity, int) or price < 0 or quantity < 0:
raise ValueError("Price and quantity must be nonnegative integers")
subtotal += price * quantity
return (subtotal * (100 - discount_percent) + 50) // 100