Define a simple set of e-commerce shipping rules in Python. Example: Free shipping for orders above $100, $5 flat rate for standard shipping, and $15 for express shipping. Print the shipping cost for 3 example orders.
- Define a function
calculate_shipping(order_amount, shipping_type)
that takes two inputs:order_amount
(total order value)shipping_type
(either “standard” or “express”).
- Add conditions for shipping rules:
- If
order_amount > 100
, shipping cost = 0 (Free shipping). - Else if
shipping_type == "standard"
, shipping cost = 5. - Else if
shipping_type == "express"
, shipping cost = 15.
- If
- Return the shipping cost from the function.
- Test with 3 example orders:
- Example 1: $120 with standard shipping → should be Free ($0).
- Example 2: $50 with standard shipping → should be $5.
- Example 3: $80 with express shipping → should be $15.
- Print results for each example order.