Skip to content

Instantly share code, notes, and snippets.

@MorkHub
Created November 17, 2016 23:35
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 MorkHub/32eb65038ffbe32801ab5b9197fc8482 to your computer and use it in GitHub Desktop.
Save MorkHub/32eb65038ffbe32801ab5b9197fc8482 to your computer and use it in GitHub Desktop.
def exercise_02 ():
print(" Exercise 02 - Shipping Charges Calculator")
weight = input(" Enter the mass of the package (kg): ",type=float)
while not (weight > 0 and weight <= 30):
weight = input(" Invalid mass. Try again: ",type=float)
method = input(" Enter shipping method (A|S): ",type=str).upper()
while not (method in ['A','S']):
method = input(" Invalid shipping method: ",type=str)
cost = 0
if weight < 2.5:
cost = 4.95
elif weight >= 2.5 and weight < 10:
cost = 8.95
elif weight >= 10 and weight < 30:
cost = 15.95
elif weight >= 30:
cost = 22.95
if method == 'A':
cost = cost * 1.5
cost = round(cost,2)
print(" This package will cost $%s" % cost)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment