Shipping Fee Tiers

Medium ⏱ 12 min 56% acceptance ★★★★★ 4.5
Write a function shipping_fee(order_total, is_premium_member) for an e-commerce checkout. Premium members always get free shipping. Non-premium members get free shipping if order_total >= 50, pay a flat $5 fee if 20 <= order_total < 50, and pay $10 if order_total < 20.

Examples

Example 1
Input
shipping_fee(60, False)
Output
0
Explanation

Order total is 50 or more, so shipping is free.

Example 2
Input
shipping_fee(10, True)
Output
0
Explanation

Premium members always ship free.

Example 3
Input
shipping_fee(15, False)
Output
10
Explanation

Under $20 and not premium.

Constraints

  • order_total is a non-negative number.
  • is_premium_member is a boolean.

Topics

Conditional StatementsBusiness Logic

Companies

AmazonFlipkartWalmart

Hints

Hint 1

Check the premium flag first as a guard clause.

Hint 2

Then branch on order_total thresholds for the remaining case.

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