Editor

Shipping Cost

#226 · Python Basics · Beginner · 30 XP · about 5 min

An online shop charges for delivery by the weight of the parcel. Write shipping_cost(weight, order_total) that returns the delivery cost in dollars as a whole number. weight is in kilograms and order_total in dollars, and both can have decimals.

  • Up to and including 1 kg: 4 dollars
  • Over 1 kg, up to and including 5 kg: 8 dollars
  • Over 5 kg, up to and including 20 kg: 15 dollars
  • Over 20 kg: 30 dollars

Orders worth 50 dollars or more ship free, except heavy parcels: anything over 20 kg always costs 30 dollars.

Examples

shipping_cost(0.5, 20)   # returns 4
shipping_cost(12, 30)    # returns 15
shipping_cost(3, 75)     # returns 0
shipping_cost(25, 200)   # returns 30

Note

weight is always more than 0, and order_total is never negative.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.