-
-
Save codecademydev/1505dbf6876474f14c1caf228a070710 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The regular ground shipping cost calculation function | |
def ground_shipping_cost(weight): | |
flat_rate = 20.0 | |
if weight <= 2.00: | |
ground_cost = (flat_rate + (weight * 1.50)) | |
return ground_cost | |
elif weight > 2.00 and weight <= 6.00: | |
ground_cost = (flat_rate + (weight * 3.00)) | |
return ground_cost | |
elif weight > 6.00 and weight <= 10.00: | |
ground_cost = (flat_rate + (weight * 4.00)) | |
return ground_cost | |
else: | |
ground_cost = (flat_rate + (weight * 4.75)) | |
return ground_cost | |
premium_cost = 125.00 | |
# The drone shipping cost calculation function | |
def drone_shipping_cost(weight): | |
if weight <= 2.00: | |
drone_cost = weight * 4.50 | |
return drone_cost | |
elif weight > 2.00 and weight <= 6.00: | |
drone_cost = weight * 9.00 | |
return drone_cost | |
elif weight > 6.00 and weight <= 10.00: | |
drone_cost = weight * 12.00 | |
return drone_cost | |
else: | |
drone_cost = weight * 14.25 | |
return drone_cost | |
# The cheapest shipping method printed to user function | |
def print_best_cost_shipping(weight): | |
ground = ground_shipping_cost(weight) | |
premium = premium_cost | |
drone = drone_shipping_cost(weight) | |
if ground < premium and ground < drone: | |
cost = ground | |
method = "standard ground" | |
elif premium < ground and premium < drone: | |
cost = premium | |
method = "premium ground" | |
else: | |
cost = drone | |
method = "drone" | |
print( | |
"The cheapest option available is $%.2f with %s shipping." | |
%(cost, method)) | |
print(print_best_cost_shipping(4.8)) | |
print(print_best_cost_shipping(41.5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment