runtime
383 / 500
question 383 Async Python · easy

Price a basket with overlapping lookups

A checkout needs every item's price and the customer's tax rate, each from a different service. Write checkout_total(skus, get_price, get_tax_rate, region) that runs all these lookups at the same time and returns the total including tax.

Coroutineasync def checkout_total(skus, get_price, get_tax_rate, region)
Returnssum(prices) * (1 + rate) where each price is await get_price(sku) and the rate is await get_tax_rate(region)
Ruleevery lookup overlaps: the total time is the slowest single lookup

Loading your progress…

Price a basket with overlapping lookups — Python practice · Runtime