Computes the volume and total surface area of a sphere or a right circular cylinder.
Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.
Try it
Inputs
shape (string, required) one of: sphere, cylinder : Which solid to measure.
radius (number, length units, required) min 0 : Radius of the sphere or cylinder.
height (number, length units, optional) min 0 : Height of the cylinder (ignored for sphere).
Outputs
volume (cubic length units): Volume of the solid.
surface_area (square length units): Total surface area of the solid.
Steps
For a sphere of radius r: volume = (4/3) * pi * r^3; surface area = 4 * pi * r^2.
For a right circular cylinder of radius r and height h: volume = pi * r^2 * h; total surface area = 2*pi*r*h + 2*pi*r^2 (the side plus both circular ends).
Round both results to 2 decimals.
Constants
pi = 3.14159265358979 dimensionless (source: Sphere and cylinder volume and surface area formulas)
Sources
Sphere and cylinder volume and surface area formulas (Wiley, 2026-09-30T19:49:00Z) - Standard solid-geometry formulas.