From f6668dcfd8b18950fea68c49bdfb369c115e8837 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 9 Sep 2024 18:47:58 -0600 Subject: [PATCH] Added volumetric weight calculation for shipping cost. Now compares actual vs. volumetric weight and charges based on the higher one. --- Shipping_Cost_Calculator.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Shipping_Cost_Calculator.py b/Shipping_Cost_Calculator.py index 220e2f377..3e5bbc03a 100644 --- a/Shipping_Cost_Calculator.py +++ b/Shipping_Cost_Calculator.py @@ -1,12 +1,20 @@ # Shipping Cost Calculator -## Input package weight and shipping rate +## Input package weight, volume dimensions, and shipping rate weight = float(input("Enter the package weight in kilograms: ")) +length = float(input("Enter the package length in centimeters: ")) +width = float(input("Enter the package width in centimeters: ")) +height = float(input("Enter the package height in centimeters: ")) rate = float(input("Enter the shipping rate per kilogram: ")) +## Calculate volumetric weight +volumetric_weight = (length * width * height) / 5000 + +## Choose the greater between actual and volumetric weight +chargeable_weight = max(weight, volumetric_weight) + ## Calculate shipping cost -shipping_cost = weight * rate +shipping_cost = chargeable_weight * rate ## Display the result -print(f"Shipping Cost: {shipping_cost} USD") - +print(f"Shipping Cost: {shipping_cost:.2f} USD (based on {chargeable_weight:.2f} kg)")