Skip to content

Instantly share code, notes, and snippets.

@stghecker
Last active August 14, 2026 07:52
Show Gist options
  • Select an option

  • Save stghecker/6208b2ce0ed1509e4ff83c695e31fba3 to your computer and use it in GitHub Desktop.

Select an option

Save stghecker/6208b2ce0ed1509e4ff83c695e31fba3 to your computer and use it in GitHub Desktop.

📦 Volumetric Weight Calculator

A simple calculator used to determine the dimensional shipping weight (in grams) of retail items using their width, height, and length.

Check github.com/stghecker/simple-python for more.

width = 0.0
height = 0.0
length = 0.0
whl = 0.0
grams = 0.0
while True:
while True:
width = input("Width...:").replace(",", ".")
try:
width = float(width)
break
except ValueError:
print("Please input a valid number.")
while True:
height = input("Height...:").replace(",", ".")
try:
height = float(height)
break
except ValueError:
print("Please input a valid number.")
while True:
length = input("Length...:").replace(",", ".")
try:
length = float(length)
break
except ValueError:
print("Please input a valid number.")
while True:
grams = input("Grams...:").replace(",", ".")
try:
grams = float(grams)
break
except ValueError:
print("Please input a valid number.")
whl = (width * height * length) / 5
if whl >= grams:
print(f"Your product is {whl:.2f} grams (Volumetric).")
print(f"({width} * {height} * {length}) / 5")
elif grams >= whl:
print(f"Your product is {grams:.2f} grams (Actual).\n")
#STGHECKER#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment