I’m a little confused by Sal’s Shipping Project.
To calculate the cheapest shipping option, I produced the code below.
As you can see, I use if … if …else for my control flow.
Using the sample weights provided, this prints two responses: the correct one, and then the premium shipping print message, which is incorrect.
If I use if…elif…else, then it produces just the correct answer. But I don’t understand why?
Any advice very welcome!
def cheapest_option(weight):
if ground_shipping(weight) < premium_shipping and ground_shipping(weight) < drone_shipping(weight):
print("Ground Shipping is the cheapest option. It will cost $" + str(ground_shipping(weight)))
if drone_shipping(weight) < premium_shipping and drone_shipping(weight) < ground_shipping(weight):
print("Drone Shipping is the cheapest option. It will cost $" + str(drone_shipping(weight)))
else:
print("Premium Shipping is the cheapest option. It will cost $" + str(premium_shipping))