Help Sal's Shipping

I am using this code but is not giving the expected output. Please help.

def ground_shipping_cost(weight):
  if weight <= 2:
    ground_shipping_cost = 20 + 1.5*weight
  elif 2 < weight <= 6:
    ground_shipping_cost = 20 + 3*weight
  elif 6 < weight <= 10:
    ground_shipping_cost = 20 + 4*weight
  elif 10 < weight:
    ground_shipping_cost = 20 + 4.75*weight 
  return ground_shipping_cost


premium_ground_shipping_cost= 125

def drone_shipping_cost(weight):
  if weight <= 2:
   drone_shipping_cost = 4.5*weight
  elif 2 < weight <= 6:
    drone_shipping_cost = 9*weight
  elif 6 < weight <= 10:
    drone_shipping_cost = 12*weight
  elif 10 < weight:
    drone_shipping_cost= 14*weight
  return drone_shipping_cost


def print_cheapest_method(weight):

  if ground < premium and ground < drone:
    method = "Ground Shipping"
    cost = ground
  elif premium < ground and premium < drone:
    method = "Premium Ground Shipping"
    cost = premium
    method = "Drone Shipping"
    cost = drone
  print (
    "The cheapeast option available is $%f with %s shipping."
  % (cost, method)


HELP: This code is NOT showing the cheapest way to ship 4.8 pound package is using ground shipping and it will cost $34.40 and the cheapest way to ship a 41.5 pound package is using premium ground shipping and it will cost $125.00.

What am I missing? Thanks :slight_smile:

@chip7693734227 Welcome to the forums. Could you please format. you code according to this:How do I format code in my posts? Because without seeing the indenting, I can only assume:

I’m not sure you can do that in Python. Try using the multiplication operator (*).

Drone is defined in this function:

That makes it a local variable. This means that it can’t be called in the last function, like you’re doing.

I hope this helps!

1 Like

I’ve fixed the OP’s post to retain the formatting.

@chip7693734227 - you can look at the edit to see how I did that. :slight_smile:

Ignore the local variable thing; your code works there.