Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created February 13, 2021 17:36
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/42f8ada303c454794dac8bd4419bbb66 to your computer and use it in GitHub Desktop.
Save codecademydev/42f8ada303c454794dac8bd4419bbb66 to your computer and use it in GitHub Desktop.
Codecademy export
weight = 1.5
# calculate ground shipping
if weight <= 2:
cost_ground = (weight * 1.50) + 20
elif weight > 2 and weight <= 6:
cost_ground = (weight * 3) + 20
elif weight > 6 and weight <= 10:
cost_ground = (weight * 4) + 20
else:
cost_ground = (weight * 4.75) + 20
cost_premium = 125
#calculate drone shipping
if weight <= 2:
cost_drone = weight * 4.50
elif weight > 2 and weight <= 6:
cost_drone = weight * 9
elif weight > 6 and weight <= 10:
cost_drone = weight * 12
else:
cost_drone = weight * 14.25
#Determine cheapest method
if (cost_ground < cost_premium) and (cost_ground < cost_drone):
cheapest = "Ground shipping"
print("Ground shipping is your cheapest method at: $" + str(cost_ground))
elif cost_premium < cost_ground and cost_premium < cost_drone:
cheapest = "Premium ground shipping"
print("Premium shipping is your cheapest method at: $" + str(cost_premium))
elif cost_drone < cost_ground and cost_drone < cost_premium:
cheapest = "Drone shipping"
print("Drone shipping is your cheapest method at: $" + str(cost_drone))
#Calculate savings compared to the next cheapest method
if cheapest == "Ground shipping":
print("Premium ground shipping would cost: $" + str(cost_premium))
print("Drone shipping would cost: $" + str(cost_drone))
if cost_premium < cost_drone:
next_cheapest = "Premium ground shipping"
saving = cost_premium - cost_ground
else:
next_cheapest = "Drone shipping"
saving = cost_drone - cost_ground
elif cheapest == "Premium ground shipping":
print("Ground shipping will cost: $" + str(cost_ground))
print("Drone shipping will cost: $" + str(cost_drone))
if cost_ground < cost_drone:
next_cheapest = "Ground shipping"
saving = cost_ground - cost_premium
else:
next_cheapest = "Drone Shipping"
saving = cost_drone - cost_premium
elif cheapest == "Drone shipping":
print("Ground shipping will cost: $" + str(cost_ground))
print("Premium ground shipping will cost: $" + str(cost_premium))
if cost_ground < cost_premium:
next_cheapest = "Ground shipping"
saving = cost_ground - cost_drone
else:
next_cheapest = "Premium ground shipping"
saving = cost_premium - cost_drone
#Print the savings against the next cheapest method
print("You will save $" + str(saving) + " by picking " + cheapest + "!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment