35 lines
1.1 KiB
Markdown
35 lines
1.1 KiB
Markdown
# 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:
|
||
|
||
```bash
|
||
pip install -e ".[dev]"
|
||
python -m pytest
|
||
```
|
||
|
||
## Billing rules (specification)
|
||
|
||
1. `base_price` is a non-negative number. A negative `base_price` raises
|
||
`ValueError`.
|
||
2. `discounts` is a sequence of percentages. Each discount must be within
|
||
`0`–`100` inclusive; any discount outside that range raises `ValueError`.
|
||
3. **Stacking is sequential (compounding).** Each discount applies to the
|
||
price left over by the previous one — discounts are never summed.
|
||
|
||
Example: `100.00` with discounts `[10, 20]`:
|
||
- after 10%: `90.00`
|
||
- after 20% of the remainder: `72.00` ← final price
|
||
|
||
4. 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`.
|