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

Function vol_pyramid

maths/volume.py:290–316  ·  view source on GitHub ↗

r""" | Calculate the Volume of a Pyramid. | Wikipedia reference: https://en.wikipedia.org/wiki/Pyramid_(geometry) :return: :math:`\frac{1}{3} \cdot B \cdot h` >>> vol_pyramid(10, 3) 10.0 >>> vol_pyramid(1.5, 3) 1.5 >>> vol_pyramid(1.6, 1.6) 0.8533333333333335

(area_of_base: float, height: float)

Source from the content-addressed store, hash-verified

288
289
290def vol_pyramid(area_of_base: float, height: float) -> float:
291 r"""
292 | Calculate the Volume of a Pyramid.
293 | Wikipedia reference: https://en.wikipedia.org/wiki/Pyramid_(geometry)
294
295 :return: :math:`\frac{1}{3} \cdot B \cdot h`
296
297 >>> vol_pyramid(10, 3)
298 10.0
299 >>> vol_pyramid(1.5, 3)
300 1.5
301 >>> vol_pyramid(1.6, 1.6)
302 0.8533333333333335
303 >>> vol_pyramid(0, 0)
304 0.0
305 >>> vol_pyramid(-1, 1)
306 Traceback (most recent call last):
307 ...
308 ValueError: vol_pyramid() only accepts non-negative values
309 >>> vol_pyramid(1, -1)
310 Traceback (most recent call last):
311 ...
312 ValueError: vol_pyramid() only accepts non-negative values
313 """
314 if height < 0 or area_of_base < 0:
315 raise ValueError("vol_pyramid() only accepts non-negative values")
316 return area_of_base * height / 3.0
317
318
319def vol_sphere(radius: float) -> float:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected