Calculating the cheapest price

Im currently at Sal’s Shipping and done with it but I’m curious…
What can I add to make the code spit out what shipping method would be best for said weight (“vikt” in swedish)?
If there is any improvements I could be doing at this stage of the course don’t mind letting me know, would be much appreciated. Im gonna save this piece of code just because it peaked my interest. This sure is fun!

Sadly my vars are in sweinglish, sorry!
vikt = weight
pris = price of 1st shipping method
priss = price of 2nd shipping method
drone_pris = price of 3rd shipping method.

My code:

vikt = 41.5
pris = 0

# Ground Shipping
if vikt <= 2:
  pris = (vikt * 1.50 + 20)
elif vikt < 6:
  pris = (vikt * 3.00 + 20)
elif vikt < 10:
  pris = (vikt * 4.00 + 20)
else:
  pris = (vikt * 4.75 + 20)
print("Ground shipping: ", pris)

# Ground Shipping Premium
priss = 125
print("Ground Shipping premium: ", priss)

# Drone shipping
drone_pris = 0
if vikt <= 2:
  drone_pris = (vikt * 4.50)
elif vikt < 6:
  drone_pris = (vikt * 9.00)
elif vikt < 10:
  drone_pris = (vikt * 12.00)
else:
  drone_pris = (vikt * 14.25)

print("Med Drone shipping kostar det: ", drone_pris)

There is a min() method in python that returns the smallest of it’s arguments. It’s a good exercise to come up with an algorithm that uses this (or something like it) :slight_smile:

E.g.:

x = min(15, 1000, -2)
print(x)
#what's the output?
1 Like