Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created October 31, 2018 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codecademydev/149f9a8d308401fd7c2f04561630f545 to your computer and use it in GitHub Desktop.
Save codecademydev/149f9a8d308401fd7c2f04561630f545 to your computer and use it in GitHub Desktop.
Codecademy export
def ground_shipping_cost(weight):
if weight <= 2:
return weight * 1.5 + 20
elif weight <= 6:
return weight * 3 + 20
elif weight <= 10:
return weight * 4 + 20
else:
return weight * 4.75 + 20
print(ground_shipping_cost(8.4))
premium_ground_cost = 125
def drone_shipping_cost(weight):
if weight <= 2:
return weight * 4.5
elif weight <= 6:
return weight * 9
elif weight <= 10:
return weight * 12
else:
return weight * 14.25
print(drone_shipping_cost(1.5))
def cheapest_shipping_option(weight):
ground = ground_shipping_cost(weight)
premium = premium_ground_cost
drone = drone_shipping_cost(weight)
if ground < premium and ground < drone:
method = "standard ground"
cost = ground
elif premium < ground and premium < drone:
method = "premium ground"
cost = premium
else:
method = "drone"
cost = drone
print("You should ship using %s shipping, it will cost $%.2f"
% (method, cost))
print(cheapest_shipping_option(4.8))
print(cheapest_shipping_option(41.5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment