1.1 KiB
Part 1 — Pricing: discount stacking
pricing/discounts.py contains apply_discounts(), used by our billing
service to price orders that carry one or more percentage discounts. The
current implementation does not follow the billing rules below, and part of
the test suite fails because of it.
Your task
Update apply_discounts() so it implements the billing rules. Run the tests
with:
pip install -e ".[dev]"
python -m pytest
Billing rules (specification)
-
base_priceis a non-negative number. A negativebase_priceraisesValueError. -
discountsis a sequence of percentages. Each discount must be within0–100inclusive; any discount outside that range raisesValueError. -
Stacking is sequential (compounding). Each discount applies to the price left over by the previous one — discounts are never summed.
Example:
100.00with discounts[10, 20]:- after 10%:
90.00 - after 20% of the remainder:
72.00← final price
- after 10%:
-
The result is rounded to 2 decimal places.
That is the whole specification. When you are done, note anything worth
mentioning in the repository-level NOTES.md.