MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / vol_cube

Function vol_cube

maths/volume.py:13–32  ·  view source on GitHub ↗

Calculate the Volume of a Cube. >>> vol_cube(1) 1.0 >>> vol_cube(3) 27.0 >>> vol_cube(0) 0.0 >>> vol_cube(1.6) 4.096000000000001 >>> vol_cube(-1) Traceback (most recent call last): ... ValueError: vol_cube() only accepts non-negative values

(side_length: float)

Source from the content-addressed store, hash-verified

11
12
13def vol_cube(side_length: float) -> float:
14 """
15 Calculate the Volume of a Cube.
16
17 >>> vol_cube(1)
18 1.0
19 >>> vol_cube(3)
20 27.0
21 >>> vol_cube(0)
22 0.0
23 >>> vol_cube(1.6)
24 4.096000000000001
25 >>> vol_cube(-1)
26 Traceback (most recent call last):
27 ...
28 ValueError: vol_cube() only accepts non-negative values
29 """
30 if side_length < 0:
31 raise ValueError("vol_cube() only accepts non-negative values")
32 return pow(side_length, 3)
33
34
35def vol_spherical_cap(height: float, radius: float) -> float:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected