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

Function vol_circular_cylinder

maths/volume.py:372–399  ·  view source on GitHub ↗

r""" | Calculate the Volume of a Circular Cylinder. | Wikipedia reference: https://en.wikipedia.org/wiki/Cylinder :return: :math:`\pi \cdot radius^2 \cdot height` >>> vol_circular_cylinder(1, 1) 3.141592653589793 >>> vol_circular_cylinder(4, 3) 150.79644737231007 >>

(radius: float, height: float)

Source from the content-addressed store, hash-verified

370
371
372def vol_circular_cylinder(radius: float, height: float) -> float:
373 r"""
374 | Calculate the Volume of a Circular Cylinder.
375 | Wikipedia reference: https://en.wikipedia.org/wiki/Cylinder
376
377 :return: :math:`\pi \cdot radius^2 \cdot height`
378
379 >>> vol_circular_cylinder(1, 1)
380 3.141592653589793
381 >>> vol_circular_cylinder(4, 3)
382 150.79644737231007
383 >>> vol_circular_cylinder(1.6, 1.6)
384 12.867963509103795
385 >>> vol_circular_cylinder(0, 0)
386 0.0
387 >>> vol_circular_cylinder(-1, 1)
388 Traceback (most recent call last):
389 ...
390 ValueError: vol_circular_cylinder() only accepts non-negative values
391 >>> vol_circular_cylinder(1, -1)
392 Traceback (most recent call last):
393 ...
394 ValueError: vol_circular_cylinder() only accepts non-negative values
395 """
396 if height < 0 or radius < 0:
397 raise ValueError("vol_circular_cylinder() only accepts non-negative values")
398 # Volume is radius squared * height * pi
399 return pow(radius, 2) * height * pi
400
401
402def vol_hollow_circular_cylinder(

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected