Files
swe-hiring/part1-pricing/README.md
2026-07-06 06:00:10 +06:00

35 lines
1.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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`.