Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created November 8, 2018 14:10
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/af06de54657e81696e5b6a36bc0113f7 to your computer and use it in GitHub Desktop.
Save codecademydev/af06de54657e81696e5b6a36bc0113f7 to your computer and use it in GitHub Desktop.
Codecademy export
def ground_shipping(weight):
if weight > 10.0:
return weight * 4.75 + 20.0
elif weight > 6.0 and weight <= 10.0:
return weight * 4.00 + 20.0
elif weight > 2.0 and weight <= 6.0:
return weight * 3.00 + 20.0
else:
return weight * 1.50 + 20.0
print(ground_shipping(8.4))
premium_ground_shipping = 125.0
def drone_shipping(weight):
if weight > 10.0:
return weight * 14.25 + 0.0
elif weight > 6.0 and weight <= 10.0:
return weight * 12.00 + 0.0
elif weight > 2.0 and weight <= 6.0:
return weight * 9.00 + 0.0
else:
return weight * 4.50 + 0.0
print(drone_shipping(1.5))
def find_lowest(weight):
shipping_method = ''
ground_cost = ground_shipping(weight)
drone_cost = drone_shipping(weight)
if ground_cost < drone_cost and ground_cost < premium_ground_shipping:
shipping_method = 'ground'
return shipping_method, ground_cost
elif drone_cost < ground_cost and drone_cost < premium_ground_shipping:
shipping_method = 'drone'
return shipping_method, drone_cost
else:
shipping_method = 'premium ground'
return shipping_method, premium_ground_shipping
lowest_cost = 0.0
lowest_shipping_method = ''
lowest_shipping_method, lowest_cost = find_lowest(4.8)
print('The lowest method is: ' + lowest_shipping_method + ' at a cost of $' + str(lowest_cost) + '.')
lowest_shipping_method, lowest_cost = find_lowest(41.5)
print('The lowest method is: ' + lowest_shipping_method + ' at a cost of $' + str(lowest_cost) + '.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment