Skip to content

Instantly share code, notes, and snippets.

@JohnsonLuu
Created May 29, 2020 08:44
Show Gist options
  • Save JohnsonLuu/b849b91181e9c55ffe5e66086efa3e33 to your computer and use it in GitHub Desktop.
Save JohnsonLuu/b849b91181e9c55ffe5e66086efa3e33 to your computer and use it in GitHub Desktop.
"""
Write a program that asks the user for the weight of their package and then tells them which method of shipping is cheapest and how much it will cost to ship their package using Sal’s Shippers.
"""
def ground_shipping(weight):
flat = 20
# can also do if, elif instead of all if statements
if (weight <= 2):
return (1.5 * weight) + flat
if (weight > 2 and weight <= 6):
return (3.0 * weight) + flat
if (weight > 6 and weight <= 10):
return (4.0 * weight) + flat
if (weight > 10):
return (4.75 * weight) + flat
print(ground_shipping(8.40))
#global variable
premium_ground_shipping = 125
def drone_shipping(weight):
flat = 0
# can also do if, elif instead of all if statements
if (weight <= 2):
return (4.5 * weight) + flat
if (weight > 2 and weight <= 6):
return (9.0 * weight) + flat
if (weight > 6 and weight <= 10):
return (12.0 * weight) + flat
if (weight > 10):
return (14.25 * weight) + flat
print(drone_shipping(1.5))
def cheapest_shipping(weight):
groundshipping = ground_shipping(weight)
droneshipping = drone_shipping(weight)
if(groundshipping < droneshipping and groundshipping < premium_ground_shipping):
return "The best method is ground shipping, it would cost " + str(groundshipping)+ ".\n"
elif(groundshipping > droneshipping and droneshipping < premium_ground_shipping):
return "The best method is droneshipping, it would cost " + str(droneshipping)+ ".\n"
elif(groundshipping > premium_ground_shipping and droneshipping > premium_ground_shipping):
return "The best method is premium ground shipping, it would cost " + str(premium_ground_shipping) + ".\n"
print(cheapest_shipping(4.8))
print(cheapest_shipping(41.5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment