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)
| 11 | |
| 12 | |
| 13 | def 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 | |
| 35 | def vol_spherical_cap(height: float, radius: float) -> float: |