Skip to content

Commit f6668dc

Browse files
committed
Added volumetric weight calculation for shipping cost. Now compares actual vs. volumetric weight and charges based on the higher one.
1 parent 717eb6c commit f6668dc

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Shipping_Cost_Calculator.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
# Shipping Cost Calculator
22

3-
## Input package weight and shipping rate
3+
## Input package weight, volume dimensions, and shipping rate
44
weight = float(input("Enter the package weight in kilograms: "))
5+
length = float(input("Enter the package length in centimeters: "))
6+
width = float(input("Enter the package width in centimeters: "))
7+
height = float(input("Enter the package height in centimeters: "))
58
rate = float(input("Enter the shipping rate per kilogram: "))
69

10+
## Calculate volumetric weight
11+
volumetric_weight = (length * width * height) / 5000
12+
13+
## Choose the greater between actual and volumetric weight
14+
chargeable_weight = max(weight, volumetric_weight)
15+
716
## Calculate shipping cost
8-
shipping_cost = weight * rate
17+
shipping_cost = chargeable_weight * rate
918

1019
## Display the result
11-
print(f"Shipping Cost: {shipping_cost} USD")
12-
20+
print(f"Shipping Cost: {shipping_cost:.2f} USD (based on {chargeable_weight:.2f} kg)")

0 commit comments

Comments
 (0)