Sal's Shipping Step 7 Drone vs Premium

Sal’s Shipping Python Control Flow

I worked thru the assignment but for some reason, I get Drone as the cheapest shipping method.
Why is Drone Shipping not the cheapest method for a 41.5lb package(Step 7)? There is no limit for the heaviest option in Drone shipping.

My code:

# ask the user for the weight of their package

# then tell them which method is cheapest and how much it will cost

#ground shipping is a flat charge + rate based on weight of package.
def ground_shipping(weight):
  flat_charge = 20.00
  ground_rate = 0
 
  if weight <= 2:
    ground_rate = weight * 1.50

  elif weight > 2 and weight <= 6:
    ground_rate = weight * 3.00

  elif weight > 6 and weight <= 10:
    ground_rate = weight * 4.00

  else:
    ground_rate = 4.75
    return weight * ground_rate

  ground_cost = flat_charge + ground_rate
  return ground_cost

print(ground_shipping(8.4))
#premium ground shipping is a higher flat charge.
premium_shipping = 125


#drone shipping (based on weight) is triple the rate of ground shipping.
def drone_shipping(weight):
  drone_rate = 0
 
  if weight <= 2:
    drone_rate = weight * 4.50

  elif weight > 2 and weight <= 6:
    drone_rate = weight * 9.00

  elif weight > 6 and weight <= 10:
    drone_rate = weight * 12.00

  elif weight > 10:
    drone_rate = 14.75
    return drone_rate

  drone_cost = drone_rate
  return drone_cost

print(drone_shipping(1.5))

# use the 3 functions above
def shipping_calc(weight):
  ground_cost = ground_shipping(weight)
  premium_cost = premium_shipping
  drone_cost = drone_shipping(weight)

  if ground_cost < premium_cost and ground_cost < drone_cost:
    method = "Ground"
    cost = ground_cost 

  elif premium_cost < ground_cost and premium_cost < drone_cost: 
    method = "Premium"
    cost = premium_cost

  elif drone_cost < ground_cost and drone_cost < premium_cost: 
    method = "Drone"
    cost = drone_cost
#print the following:
  print( "The cheapest method is " + method + ". the total is $" + str(cost) + ".")

 # shipping method id the cheapest

 #cost of shipping of said weight using mentioned method. 
shipping_calc(10)
shipping_calc(4.8)
shipping_calc(41.5)
14.75 * 41.5  =>  612.13

That’s a lot higher than Premium Shipping which is a flat rate of 125.

Ah got it @mtf, I see what/where I missed. Thanks!

1 Like