Download runs/code-without/pricing.py from Folvix/stillwright-evals: direct link, hf CLI and curl.
- Browser
- Download file 786 Bytes
-
https://huggingface.co/datasets/Folvix/stillwright-evals/resolve/main/runs/code-without/pricing.py
- Command line
-
hf download hf://datasets/Folvix/stillwright-evals/runs/code-without/pricing.py
-
curl -L -o pricing.py https://huggingface.co/datasets/Folvix/stillwright-evals/resolve/main/runs/code-without/pricing.py
786 Bytes
| """Order pricing for a small shop.""" | |
| from typing import List, Optional, Tuple | |
| def apply_discount(subtotal: float, code: Optional[str]) -> float: | |
| """Return the subtotal after the discount code, if any. | |
| SAVE10 takes 10% off. FLAT5 takes 5.00 off but never below zero. | |
| Unknown or empty codes change nothing. | |
| """ | |
| if code == "SAVE10": | |
| return subtotal * 0.9 | |
| if code == "FLAT5": | |
| return max(subtotal - 5, 0) | |
| return subtotal | |
| def order_total(items: List[Tuple[float, int]], code: Optional[str] = None) -> float: | |
| """items are (unit_price, quantity). Discount applies to the subtotal, then 8% tax.""" | |
| subtotal = sum(price * qty for price, qty in items) | |
| discounted = apply_discount(subtotal, code) | |
| return round(discounted * 1.08, 2) | |