Calculate tax on a shipping charge
Some regions tax shipping, others do not. Compute the tax amount on a shipping cost.
- If taxable, return floor(shippingCost × taxPercent / 100).
- If not taxable, return 0.
tax_on_shipping(shipping_cost: int, tax_percent: int, taxable: bool) → int
Where you start
def tax_on_shipping(shipping_cost: int, tax_percent: int, taxable: bool) -> int:
Worked examples
| Call | Result |
|---|---|
tax_on_shipping(8000, 10, True) | 800 |
tax_on_shipping(8000, 10, False) | 0 |
tax_on_shipping(0, 20, True) | 0 |
tax_on_shipping(5500, 8, True) | 440 |
Hint
One conditional and an integer division.
Reference solution in Python
def tax_on_shipping(shipping_cost: int, tax_percent: int, taxable: bool) -> int:
if not taxable:
return 0
return shipping_cost * tax_percent // 100