One useful idea
Cost is data plus a policy, not a number to hardcode into your program. Supply a dated rate table and a duration; return an estimate. Loading a JSON file and printing a report belong outside the pure calculation. The supplied three-provider table is invented teaching data, not current vendor pricing or currency conversion.
Decimal stores base-ten values exactly when constructed from strings: Decimal("0.035"), not Decimal(0.035) or a float. Import Decimal from decimal. Multiplication returns another Decimal; str shows its exact value. The reference uses a private 28-digit context so a caller’s precision/rounding settings do not change the estimate. Reviewed format_cost applies ROUND_HALF_UP to two places only for display; the exact result remains unrounded.
Duration is a Decimal or plain decimal string, nonnegative, at most 10,000,000 seconds and at most three decimal places. Zero is a valid zero estimate, not a fallback. Refuse booleans, floats, nonfinite values, scientific string notation, whitespace and unsupported precision. Configuration has exactly currency, as_of and rates: a real canonical ISO date, USD/EUR/GBP under this kit’s two-minor-unit display policy, 1–10 clean provider labels and plain nonnegative rate strings up to 1000 per second with six decimal places.
Return fresh currency/as_of/seconds/estimates data. Sort rows by provider; each has provider, Decimal per_second and Decimal total. Preserve the original table. A currency label does not convert USD prices to GBP: a different currency needs a separately authored table. Record the date so another learner knows which fixture you used.
Refresh first: Typed response data, Units and display rounding.
Trace a finished example
from provider_tools.core import estimate_cost, format_cost
table = {"currency": "USD", "as_of": "2026-10-07",
"rates": {"C": "0.05", "A": "0.02", "B": "0.035"}}
result = estimate_cost("12.125", table)
print(result["as_of"])
for row in result["estimates"]:
print(row["provider"], str(row["total"]),
format_cost(row["total"], result["currency"]))The pure function validates the dated table and duration, sorts A/B/C, multiplies exact decimals and returns fresh rows. Only format_cost rounds the display. The table stays unchanged and no price is fetched online.
The finished implementation is in provider_tools/core.py. Reading it is guided practice, not independent evidence.
Predict a small cost
What happens to exact USD 0.005 when displayed?
Compare your answer · self-reviewed
The display becomes USD 0.01 under ROUND_HALF_UP. The stored exact estimate stays Decimal("0.005").
Find binary money
Why not accept 12.125 as a float duration here?
Compare your answer · self-reviewed
The contract deliberately accepts a Decimal or plain decimal string, avoiding binary money and silent coercion. Explicit refusal makes the representation policy visible.
Recall provenance
Does changing currency from USD to GBP convert the rates?
Compare your answer · self-reviewed
No. A label is not an exchange-rate calculation. Author a separately dated GBP table; do not relabel USD rates as converted facts.
Try the idea in this browser
Runs in this browser · optional preparation · local project checks remain separate
Try a small function before opening your local files. Python downloads when you choose Run; if it cannot load, your code stays here and the local kit still works. The worker executes on your device, not on a DVP server. Only run code you trust: this is not a hostile-code security sandbox.
JavaScript loads the practice controls. Python starts only after Run.
The tutor button only prepares a question locally. Review it and choose Send yourself; no code is sent merely by running or opening a lesson.
Output
Errors and check feedback
Read the browser task briefs without running Python
Guided exact cost estimate
Implement estimate_cost in practice.py. You may reuse reviewed core._decimal validation and format_cost, but write your own complete table validation, ordering, private Decimal context and fresh result. Load fixtures separately. Preserve exact totals, return all configured providers and never mutate the input or silently fill missing dates/rates. Label any reviewed helper support. This browser preparation uses only invented in-memory values and reviewed helpers shown below. No HTTPX client, live request or actual sleep runs. It does not complete your local adapter, HTTP or Portfolio II task. Guided and independent attempts use changed inputs and the same declared contract.
Independent exact cost estimate
Implement estimate_cost in practice.py. You may reuse reviewed core._decimal validation and format_cost, but write your own complete table validation, ordering, private Decimal context and fresh result. Load fixtures separately. Preserve exact totals, return all configured providers and never mutate the input or silently fill missing dates/rates. Label any reviewed helper support. This browser preparation uses only invented in-memory values and reviewed helpers shown below. No HTTPX client, live request or actual sleep runs. It does not complete your local adapter, HTTP or Portfolio II task. Guided and independent attempts use changed inputs and the same declared contract.
Change it, then build your own
One controlled change
Change duration to 0.25 and rate A to 0.02; compare exact 0.005 with its display. Then change the as_of date and author a fresh GBP table. Try a float duration and an invalid calendar date.
Your independent task
Implement estimate_cost in practice.py. You may reuse reviewed core._decimal validation and format_cost, but write your own complete table validation, ordering, private Decimal context and fresh result. Load fixtures separately. Preserve exact totals, return all configured providers and never mutate the input or silently fill missing dates/rates. Label any reviewed helper support.
What success looks like
The build2 group passes exact three-provider totals, sorted/fresh data, changed configuration, zero/boundary values, caller-context independence and refusal cases. Display formatting is separately checked. Passing invented-price tests does not validate any current vendor price.
Hint 1 · a question
Separate configuration loading, exact calculation and display. Which part can be tested without files or HTTP?
Hint 2 · a concept cue
Validate duration/date/currency/rates first. Sort labels and create new rows under a private Decimal context; leave the caller’s table alone.
Hint 3 · a localized example
Decimal("0.035") is an exact input. A row’s total can be duration * rate. Do not quantize that total; reviewed format_cost handles presentation later.
Need the complete worked solution?
Open provider_tools/core.py from the kit. Trace it, close it, then try fresh inputs in your own files. Treat the attempt as guided; seeing the solution does not award a practical pass.
Course help is guidance, not independent evidence. With JavaScript, opening help records guidance locally; otherwise note it in your README. Reset does not erase that history.
Repair a failed check
If totals depend on the caller’s precision, use localcontext(Context(prec=28)) rather than a bare inherited context. If totals become floats, remove float conversion. If the exact value is rounded, move rounding into display. If missing fields quietly pass, compare the complete configuration key set.
NotImplementedError means a practice stub is still unfinished. Read the failing test name and the last error line. Change one behavior, rerun that build, then rerun all implemented builds.
Show it works on new inputs
Author three invented providers in a dated GBP table with a new duration and one zero rate. Predict exact totals, verify changed-input results and show input immutability. Explain why these fixtures are not live price or FX evidence.
Self-review: name the input, result, refused case and reason. Your local test output and explanation are separate from a quiz score; this page does not certify a pass.
Keep the idea
Keep calculation exact and provenance visible. Display rounding and currency conversion are separate decisions.