Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created September 25, 2020 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/6bfeeff8a6c547707516421f79da92aa to your computer and use it in GitHub Desktop.
Save codecademydev/6bfeeff8a6c547707516421f79da92aa to your computer and use it in GitHub Desktop.
Codecademy export
# Sal's Shipping - Python Project
# Finding the Cheapest Shipping Method
# STEP 1: Ship cost by weight - Normal Ground Shipping
def cost_gnd_ship(weight):
if (weight <= 2):
cost = (weight*1.50) + 20.00
elif (weight > 2) and (weight <= 6):
cost = (weight*3.00) + 20.00
elif (weight > 6) and (weight <= 10):
cost = (weight*4.00) + 20.00
else:
cost = (weight*4.75) + 20.00
return cost
# STEP 2: Testing the function with a package of 8.4 lb
print("The price of this shipment will be: US$ " + str(cost_gnd_ship(8.4)))
# STEP 3: Including the Premium Gorund Shipping Cost
premium_gnd_ship = 125
# STEP 4: Defining the function for cost of the drone shipping
def cost_drone_gnd_ship(weight):
if (weight <= 2):
cost = weight*4.50
elif (weight > 2) and (weight <= 6):
cost = weight*9.00
elif (weight > 6) and (weight <= 10):
cost = weight*12.00
else:
cost = weight*14.25
return cost
# STEP 5: Testing the drone function with a package of 1.5 lb
print("The price of this shipment will be: US$ " + str(cost_drone_gnd_ship(1.5)))
# STEP 6: Advising te customer about the best shipping method
def best_choice_ship(weight):
gnd = cost_gnd_ship(weight)
drn = cost_drone_gnd_ship(weight)
prm = premium_gnd_ship
if (gnd < drn) and (gnd < prm):
return "The lower cost method for this shipment is the Ground shipping and it costs: US$ " + str(gnd)
elif (drn < gnd) and (drn < prm):
return "The lower cost method for this shipment is the Drone shipping and it costs: US$ " + str(drn)
else:
return "The lower cost method for this shipment is the Premium shipping and it costs: US$ " + str(prm)
# STEP 7: Testing the function that suggests the best price with the best method with two values (and many others)
print(best_choice_ship(0.8))
print(best_choice_ship(4.8))
print(best_choice_ship(41.5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment