r""" | Calculate the Volume of a Sphere. | Wikipedia reference: https://en.wikipedia.org/wiki/Sphere :return: :math:`\frac{4}{3} \cdot \pi \cdot r^3` >>> vol_sphere(5) 523.5987755982989 >>> vol_sphere(1) 4.1887902047863905 >>> vol_sphere(1.6) 17.15728467880506
(radius: float)
| 317 | |
| 318 | |
| 319 | def vol_sphere(radius: float) -> float: |
| 320 | r""" |
| 321 | | Calculate the Volume of a Sphere. |
| 322 | | Wikipedia reference: https://en.wikipedia.org/wiki/Sphere |
| 323 | |
| 324 | :return: :math:`\frac{4}{3} \cdot \pi \cdot r^3` |
| 325 | |
| 326 | >>> vol_sphere(5) |
| 327 | 523.5987755982989 |
| 328 | >>> vol_sphere(1) |
| 329 | 4.1887902047863905 |
| 330 | >>> vol_sphere(1.6) |
| 331 | 17.15728467880506 |
| 332 | >>> vol_sphere(0) |
| 333 | 0.0 |
| 334 | >>> vol_sphere(-1) |
| 335 | Traceback (most recent call last): |
| 336 | ... |
| 337 | ValueError: vol_sphere() only accepts non-negative values |
| 338 | """ |
| 339 | if radius < 0: |
| 340 | raise ValueError("vol_sphere() only accepts non-negative values") |
| 341 | # Volume is 4/3 * pi * radius cubed |
| 342 | return 4 / 3 * pi * pow(radius, 3) |
| 343 | |
| 344 | |
| 345 | def vol_hemisphere(radius: float) -> float: |
no outgoing calls
no test coverage detected