Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created November 24, 2020 14:06
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/e14043768585e087beec2da332e2f2cb to your computer and use it in GitHub Desktop.
Save codecademydev/e14043768585e087beec2da332e2f2cb to your computer and use it in GitHub Desktop.
Codecademy export
# function for ground shipping
def ground_shipping (weight, cost= 20 ):
if weight <= 2:
return (weight * 1.50) + cost
elif weight >= 2 and weight <= 6 :
return (weight * 3.0) + cost
elif weight >= 6 and weight <= 10 :
return (weight * 4.0) + cost
return (weight * 4.75) + cost
premium_ground_shipping = 125
# function for drone shipping
def drone_shipping (weight, cost = 0):
if weight <= 2:
return (weight * 4.50) + cost
elif weight >= 2 and weight <= 6 :
return (weight * 9.0) + cost
elif weight >= 6 and weight <= 10 :
return (weight * 12.0) + cost
return (weight * 14.25) + cost
def shipping_cost (weight):
ground = ground_shipping (weight)
premium = premium_ground_shipping
drone = drone_shipping (weight)
if ground < premium and ground < drone:
method = 'standard ground'
cost = ground
elif premium < ground and premium < drone:
method = 'premium'
cost = premium
else:
method = 'drone'
cost = drone
print (
"The Cheapest Option Available is $%.2f with %s shipping."
% (cost, method)
)
print(drone_shipping(1.5))
print(shipping_cost(4.8))
print(shipping_cost(41.5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment