Skip to content

Instantly share code, notes, and snippets.

@somodiferenc
Last active April 1, 2020 11:04
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 somodiferenc/e9b48375291cb8c4c2b0b13be07fa556 to your computer and use it in GitHub Desktop.
Save somodiferenc/e9b48375291cb8c4c2b0b13be07fa556 to your computer and use it in GitHub Desktop.
Python_practice_project
price_ground_1 = 1.50
price_ground_2 = 3.0
price_ground_3 = 4.0
price_ground_4 = 4.75
price_premium = 125.0
price_drone_1 = 4.50
price_drone_2 = 9.0
price_drone_3 = 12.0
price_drone_4 = 14.25
# function to calculate ground shipping cost
def cost_ground_shipping(weight):
cost1 = 20 + weight * price_ground_1
cost2 = 20 + weight * price_ground_2
cost3 = 20 + weight * price_ground_3
cost4 = 20 + weight * price_ground_4
if weight < 2:
return cost1
elif 2 < weight <= 6:
return cost2
elif 6 < weight <= 10:
return cost3
elif weight > 10:
return cost4
#print(cost_ground_shipping(8.4))
# function to calculate drone shipping cost
def cost_drone_shipping(weight):
cost1 = weight * price_drone_1
cost2 = weight * price_drone_2
cost3 = weight * price_drone_3
cost4 = weight * price_drone_4
if weight < 2:
return cost1
elif 2 < weight <= 6:
return cost2
elif 6 < weight <= 10:
return cost3
elif weight > 10:
return cost4
# compare different shipping options
def compare(weight):
ground = cost_ground_shipping(weight)
drone = cost_drone_shipping(weight)
if ground < drone and ground < price_premium:
return "The cheapest shipping method is ground shipping. " + "It costs " + str(ground)
elif drone < ground and drone < price_premium:
return "The cheapest shipping method is drone shipping. " + "It costs " + str(drone)
elif price_premium < ground and price_premium < drone:
return "The cheapest shipping method is premium ground shipping. " + "It costs " + str(price_premium)
#test
print(compare(4.8))
print(compare(41.5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment