Review this generated order-pricing function.
Price an order in integer cents, reject non-positive quantities, apply the best supplied discount, keep customer email out of logs, and return the total plus the average item value.
Python
def price_order(
items: list[dict[str, int]],
customer_email: str,
discounts: list[int] = [],
) -> dict[str, int]:
discounts.append(0)
subtotal = sum(
item["unit_cents"] * item["quantity"]
for item in items
)
discounted = subtotal - max(discounts)
tax = int(discounted * 0.2)
print(f"priced {customer_email}: {subtotal}")
if len(items) == 0:
average = 0
else:
average = sum(
item["unit_cents"] * item["quantity"]
for item in items
) // len(items)
return {"total_cents": discounted + tax, "average_cents": average}
generated code is illustrative, not from any one model