Drill

ProblemsPython › billing

Look up the tax rate for a region

easybillingPython

A billing system stores tax rates by region code. Look up the rate; an unknown region is not taxed.

region_tax(region_rates: map<string, int>, region: string) → int

Solve it in the editor →

Where you start

def region_tax(region_rates: dict[str, int], region: str) -> int:
    

Worked examples

CallResult
region_tax({"US": 700, "EU": 1900, "TR": 1800}, "EU")1900
region_tax({"US": 700}, "UK")0
region_tax({}, "US")0
region_tax({"DE": 1900, "FR": 2000}, "DE")1900

Hint

Map lookup with a default.

Reference solution in Python
def region_tax(region_rates: dict[str, int], region: str) -> int:
    return region_rates.get(region, 0)

The same problem in another language

More billing problems in Python