Taza Mind

A fusion of fresh thoughts and AI intelligence

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.

  1. Define a functioncalculate_shipping(order_amount, shipping_type) that takes two inputs:
    • order_amount (total order value)
    • shipping_type (either “standard” or “express”).
  2. 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.
  3. Return the shipping cost from the function.
  4. 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.
  5. Print results for each example order.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *