Keyword-Only Shipping Quote

Medium ⏱ 12 min 51% acceptance ★★★★☆ 4.4
Write a function shipping_quote(weight_kg, *, express=False, insured=False) that computes a shipping cost. Base cost is weight_kg * 50. If express is True, add a flat 100. If insured is True, add 20. express and insured must be passed by keyword only (the * enforces this) and both default to False.

Examples

Example 1
Input
shipping_quote(2)
Output
100
Explanation

Base cost only: 2 * 50 = 100.

Example 2
Input
shipping_quote(2, express=True, insured=True)
Output
220
Explanation

100 base + 100 express + 20 insured = 220.

Constraints

  • weight_kg is a positive number.
  • express and insured must be passed as keywords, never positionally.

Topics

Functionskeyword-only arguments

Companies

WalmartAmazon

Hints

Hint 1

A bare * in the signature forces everything after it to be keyword-only.

Hint 2

Add each surcharge conditionally.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.