-
-
Save codecademydev/ef1f152225dc8fb5a38fce782345f47a 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
def ground_shipping(weight): | |
if weight <= 2: | |
ground_shipping = 1.50 | |
elif weight <= 6: | |
ground_shipping = 3 | |
elif weight <= 10: | |
ground_shipping = 4 | |
else: | |
ground_shipping = 4.75 | |
#all packages that weight over 10lbs will be charged through the 'else' statement | |
return 20 + (ground_shipping * weight) | |
# need to multiply the price per pound (ground_shipping) with the weight of the package and add the flat charge to get the final cost of a given package | |
print(ground_shipping(8.4)) | |
#always test your functions - in this case we are testing to see the cost of ground shipping for a 8.4lb package (should be $53.6) | |
premium_ground_shipping = 125 | |
# a variable : flat charge for premium ground shipping | |
def drone_shipping(weight): | |
if weight <= 2: | |
drone_shipping = 4.50 | |
elif weight <=6: | |
drone_shipping = 9 | |
elif weight <=10: | |
drone_shipping = 12 | |
else: | |
drone_shipping = 14.25 | |
return weight * drone_shipping | |
print(drone_shipping(1.5)) | |
#always test your functions - in this case we are testing to see the cost of drone shipping for a 1.5lb package (should be $6.75) | |
def cheapest_shipping_method(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 drone < premium and drone <ground: | |
method = "drone" | |
cost = drone | |
else: | |
method = "premium ground" | |
cost = premium | |
print( | |
"The cheapest option available is $%.2f with %s shipping." | |
% (cost, method) | |
) | |
cheapest_shipping_method(4.8) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment