# build a Python dictionary of volumes
from math import sqrt
φ = (1 + sqrt(5))/2
volumes = dict((("tetrahedron", 1),
("cube", 3),
("octahedron", 4),
("rhombic dodecahedron", 6)))
modules = dict((("A module", 1/24),
("B module", 1/24),
("T module", 1/24),
("E module", (sqrt(2)/8) * (φ ** -3)),
("S module", (φ **-5)/2)))
volumes.update(modules)
template = "| {s:30} | {v:7} |"
print(template.format(s = "SHAPE", v = "VOLUME"))
print("-" * 45)
template = "| {s:30} | {v:6.5f} |"
# sorted by volume, not shape name
for shape, volume in sorted(tuple(volumes.items()), key=lambda x: x[1]):
print(template.format(s=shape, v=volume))
| SHAPE | VOLUME | --------------------------------------------- | A module | 0.04167 | | B module | 0.04167 | | T module | 0.04167 | | E module | 0.04173 | | S module | 0.04508 | | tetrahedron | 1.00000 | | cube | 3.00000 | | octahedron | 4.00000 | | rhombic dodecahedron | 6.00000 |