From 96c06e08ae69e7b629bfba552042312b754b7633 Mon Sep 17 00:00:00 2001 From: Elliot Harrison <63355920+Magpie10@users.noreply.github.com> Date: Tue, 27 Feb 2024 13:28:39 +0100 Subject: [PATCH] Update shipping.py This is a more concise shipping calculator that combines the two if statements to save space. --- 2-control-flow/sals-shipping/shipping.py | 36 ++++++++---------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/2-control-flow/sals-shipping/shipping.py b/2-control-flow/sals-shipping/shipping.py index 07d8cbf..41b5f80 100644 --- a/2-control-flow/sals-shipping/shipping.py +++ b/2-control-flow/sals-shipping/shipping.py @@ -1,36 +1,24 @@ # Sal's Shipping # Sonny Li -weight = 80 - -# Ground Shipping 🚚 +weight = 1.5 +cost_ground = 0 +cost_ground_premium = 125 +cost_drone = 0 if weight <= 2: cost_ground = weight * 1.5 + 20 -elif weight <= 6: - cost_ground = weight * 3.00 + 20 -elif weight <= 10: - cost_ground = weight * 4.00 + 20 -else: - cost_ground = weight * 4.75 + 20 - -print("Ground Shipping $", cost_ground) - -# Ground Shipping Premimum 🚚💨 - -cost_ground_premium = 125.00 - -print("Ground Shipping Premimium $", cost_ground_premium) - -# Drone Shipping 🛸 - -if weight <= 2: cost_drone = weight * 4.5 elif weight <= 6: - cost_drone = weight * 9.00 + cost_ground = weight * 3 + 20 + cost_drone = weight * 9 elif weight <= 10: - cost_drone = weight * 12.00 + cost_ground = weight * 4 + 20 + cost_drone = weight * 12 else: + cost_ground = weight * 4.75 + 20 cost_drone = weight * 14.25 -print("Drone Shipping: $", cost_drone) \ No newline at end of file +print(f"Ground shipping standard: {cost_ground}") +print(f"Drone shipping: {cost_drone}") +print(f"Ground premium cost: {cost_ground_premium}")