Sal's Shipping Python: Does my code have any faults?

I checked my code with multiple numbers. I just want to make sure it’s ok before I move on. Thank you!

def ground_shipping_cost(weight):
  cost = 0
  if (weight <= 2):
    cost = (weight * 1.50) + 20
  elif (weight <= 6):
    cost = (weight * 3.00) + 20
  elif (weight <= 10):
    cost = (weight * 4.00) + 20
  else:
    cost = (weight * 4.75) + 20
  return cost

premground_shipping_cost = 125

def drone_shipping_cost(weight):
  cost = 0
  if (weight <= 2):
    cost = (weight * 4.50)
  elif (weight <= 6):
    cost = (weight * 9.00)
  elif (weight <= 10):
    cost = (weight * 12.00)
  else:
    cost = (weight * 14.25)
  return cost

def cheapest_option(weight):
  ground = ground_shipping_cost(weight)
  premium = premground_shipping_cost
  drone = drone_shipping_cost(weight)
  if (ground > drone) and (ground < premium):
    cost = drone
    print("Use Drone Shipping. It costs " + str("%.2f" % cost) + " dollars.")
  elif not (ground > drone) and (ground < premium):
    cost = ground
    print("Use Standard Ground Shipping. It costs " + str("%.2f" % cost) + " dollars.")
  elif not (ground > drone) and not (ground < premium):
    cost = premium
    print("Use Premium Ground Shipping. It costs " + str("%.2f" % cost) + " dollars.")
  return ""
    
print(cheapest_option(4.8))
print(cheapest_option(41.5))

Thank you in advance!
Link to project: https://www.codecademy.com/courses/learn-python-3/projects/sals-shipping

Your code works well, and has no inherent bugs (I presume that the answers should be Standard then Premium).

1 Like

If you have values like this then your code won’t figure out which is cheapest

ground = 100
drone = 99
premium = 30